How the Callout Works
Here is what the PostUpdate
callout method does. Whenever a lead record's status is changed, it fires the PostUpdate
method, which serializes the postImageEntityXml
to a dynamic entity and calls the ProcessLeads
method if the name of the entity is lead
. The ProcessLeads
method writes the postImageEntityXml
to a text file. To run the application, follow these steps.
- Launch the CRM browser and navigate to the Sales tab.
- Click on Leads, and then click on New.
- Enter the first name, last name, and country, and then click on Save, and finally, Close.
- Double-click on the newly created record to open it in edit mode.
- Change the status from "New" to something else.
- Open the text file whose name begins with "Crmcallout" on the C:\ drive.
- Compare the values in the text file with the newly updated record in the CRM (see Figure 1).
|Figure 1. Updated Record: Your newly updated record should look similar to this one.|
Some important points that you should note while developing a callout are:
Deploying Callout Assemblies
- You should not access System.Console or use Pinvoke in the callout code.
- Make sure that you don't update the entity itself in its post-callout; doing so will cause a deadlock. If you must do that, put the required code in place to avoid deadlocks.
- MSCRM callouts do not call Dispose methods; therefore, you should write your code so it explicitly releases resources.
When you finished developing the assembly, place it in the C:\Program Files\Microsoft CRM\server\bin\assembly
folder. Note that you don't need to deploy the Microsoft.Crm.Platform.Callout.Base.dll
because it's already installed in the GAC. Finally, restart IIS to force the changes to take effect. If you get an error similar to the one in Figure 2
, cycle IIS again.
|Figure 2. Typical IIS Error: IIS can't copy files when they're in use.|
Using MSCRM callouts, you can validate CRUD operations and integrate your CRM application with other applications, such as ERPs, SharePoint Portals, etc. In a nutshell, you've seen how to build a callout assembly that exposes methods triggered when specific corresponding MSCRM events fire. Building the callout assembly is straightforward, but when you finish creating and deploying the assembly, remember to reset IIS before executing the application. The second article in this series delves into some more advanced issues.