Sunday, October 31, 2010

Changes in CRM 2011 plugins

There are a lot of syntax and functional changes in MSCRM 2011 plugins. I have listed some of them below:
1. New References
• System.ServiceModel
• System.Runtime.Serialization

2. Microsoft.Crm.Sdk has been replaced by Microsoft.Xrm.Sdk

3. The default parameter for execute method has been changed from
IPluginExecutionContext to IServiceProvide


public void Execute(IServiceProvider serviceProvider)

4. IpluginExecutionContext has been changed to a type of service and to get the reference use the following syntax.

IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));

5. ICrmService has been changed to IOrganizationService

IOrganizationServiceFactory serviceFactory =
IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

6. Dynamic entity has been changed to “Entity”

if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
}


7. Dynamic Entity’s properties syntax has been changed to attributes

entity.Attributes.Contains("accountnumber")

8. Strongly typed classes (account, contact) are missing in Microsoft.XRM.Sdk assembly but there is an exception to this.

9. CRM 2011 provides the crm utility called “crmsvcutil” to generate strongly typed classes that can be used in plugins.

10. Strongly typed classes has been changed to use like loosely typed classes.
Task task = new Task();
Task[“description”] = ”test description”

11. No more soap exception
catch (FaultException ex)

Tuesday, October 26, 2010

Step by step plugin tutorial for CRM 2011

This is a step by step guide to create a plug-in in CRM 2011.

1. Create a class library project in vs2010.
2. Sign the assembly by using the Signing tab of the project's properties sheet.
3. Add references to microsoft.crm.sdk.proxy , Microsoft.xrm.sdk ,
System.ServiceModel and System.Runtime.Serialization.
4. Here is code for this tutorial. This plugin will check if the account number
field is empty, create a task for the user to fill this up.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;
using System.ServiceModel;

namespace CRMPlugin1
{
public class createNote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));


// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];



try
{
//check if the account number exist

if (entity.Attributes.Contains("account number") == false)
{

//create a task
Entity task = new Entity("task");
task["subject"] = "Account number is missing";
task["regardingobjectid"] = new EntityReference("account",new Guid(context.OutputParameters["id"].ToString()));

//adding attribute using the add function
// task["description"] = "Account number is missng for the following account. Please enter the account number";
task.Attributes.Add("description", "Account number is missng for the following account. Please enter the account number");



// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


// Create the task in Microsoft Dynamics CRM.
service.Create(task);


}
}

catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}

}

}
}//end class
}//end name space


5. Compile the code and register it on the registration tool provided with sdk.
6. Register it on the post create event of account entity.
Note :check the sdk for instructions to register a plugin

Thanks

Monday, October 25, 2010

CRM 2011 Beta - Sharepoint Integration Bug

Hi

I am playing around with crm 2011 beta from last few weeks and I found a bug in crm-sharepoint integration. It occurs when you select your document management folder structure based on the entity, in my case I chose "account".

If you create an account with spaces ("my test account"), click on the documents on left navigation bar, the system will prompt you to create a folder (htttp://localhost/account/my test account"). Press yes and system will create a folder "my test account" in sharepoint.

Now create a new opportunity ("opportunity 1") and click on the documents on the left navigation bar. The system will prompt you to create a folder ("htttp://localhost/account/my test account/opportunity/opportuynity 1"). Press yes,
the system will come back with the following message:




and the system will create a folder anyway.

Now if you create another record like opportunity or invoice and click on documents the system will ask you to create the folder like ("htttp://localhost/account/my-test- account/opportunity/opportuynity 3"). Press yes and the system will create a new account folder "my-test- account" and create the "opportunity/opportunity 3" folder.





Every time you create a new folder for any related entity it will work properly and create all the sub folders in "my-test- account". But the first opportunity record still displays the error message. You do have an option to correct the location, buts it’s a bug and you end up with 2 folders, one with spaces and one with "-" s.




Good bye.

Thursday, October 21, 2010

Using XRM SDK in MSCRM 4.0 Plugins

I am back and very excited about MSCRM 5.0. But today I am putting a sample to use xrm sdk in plugins. By default there no method in XrmDataContext class to pass plugin context.
But there are ways around it. You can pass the connection as string or as crmconection as follow

Microsoft.Xrm.Client.CrmConnection.Parse(
"Authentication Type=Integrated; Server=http://localhost:" +
new Uri(Microsoft.Win32.Registry.LocalMachine.OpenSubKey ("SOFTWARE\\Microsoft\\MSCRM", false).GetValue("ServerUrl").ToString()).Port +
"/" + context.OrganizationName)

This worked for me.

Here is sample code I have used to create a note for an account



public void Execute(IPluginExecutionContext context)
{
try
{
Guid ID = new Guid();


switch (context.MessageName)
{
case "Create":
ID = new Guid(context.OutputParameters.Properties["id"].ToString());
break;
case "Update":
ID = (Guid)((Microsoft.Crm.Sdk.Key)((Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters.Properties["Target"]).Properties[context.PrimaryEntityName + "id"]).Value;
break;
case "SetState":
ID = (Guid)((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["EntityMoniker"]).Id;
break;
case "SetStateDynamicEntity":
ID = (Guid)((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["EntityMoniker"]).Id;
break;
case "Delete":
ID = (Guid)((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["Target"]).Id;
break;

}


var crm = new XRM.MyDataContext(context);

var note = new XRM.annotation()
{
subject = "My XRM Note",
notetext = "This is my XRM Sample.",
Account_Annotation_id = ID,
objecttypecode = "account",

};
crm.AddToannotations(note);
crm.SaveChanges();

Monday, May 18, 2009

Bulk Emails with attachments using MSCRM Templates

Hi Guyz,
I am working on a custom application from last few weeks. The application will send bulk emails with attachments using MSCRM templates. This functionality does not exist in MSCRM.

The coding is almost finished. I am working on a deployment package.
Any suggestions welcome. Here are few screen shots of the application.



  1. Choose a sender: Sender can be a user or a queue. User can send an email on behalf of another user

  2. Choose an entity: Entity can be account, contact,lead or an opportunity

  3. Choose a list: Based on the choosen entity in step 2, the system will display advanced find queries available for selected entity and sender.

  4. Choose a template: Based on the choosen entity in step 2, the system will display all the available templates available for selected entity and sender.

  5. Attach the files: Choose a file to attach and press attach butoon as shoen in the screen shot above.

  6. Files can be removed by clicking on remove link as shown in the screen shot above.

  7. The user have an option to send a test email by clicking send test email button.

Send test email button will bring up lookup screen for the entity. For e.g. Account lookup in the screen shot below


Choose the test record and email will be sent to the selected record.
Check your test email, if every thing looks alright send the bulk email by clicking Send Email button.
This application is for sale like an addon. The sale price is $3000. The price is in Australian dollars. Please conatct me if you are interested.

Thursday, May 7, 2009

MSCRM GP Connector

Hi guys, How are you all going?
I just started working on MSCRM GP Connector. I have few different versions of connector in mind.
  • First one that can be schedule to run at specified time or trigger by the user by pressing a button.
  • Second one that will use real time integration.

Hey guyz please send some suggestions, what would you like see in this connector?

Have a nice weekend.

Wednesday, April 8, 2009

MSCRM Asynchronous Service is not working

Hi guys, I have come across this problem few times now. This is preety common with upgraded deployments. If your workflows are not firing or your data imports are not working and asynchronous services are running properly. Then what's the problem?

The problem is there is an entry missing in your mscrm database.

To fix this problem update column AsyncSdkRootDomain to servername:port
(crmserver:5555) in DeploymentProperties table.

Happy Easter.......