Saturday, August 1, 2009

MS CRM : Update hotlist using plugin

Microsoft Dynamics CRM 4.0 offers a lot of functionality in terms of Customer relations management and sales process. It could be highly customised and flexible enough to satisfy the user requirement.

Microsoft Dynamics CRM 4.0, Plug ins are very powerful and are highly extensible within Dynamics CRM for overriding the limitations of Microsoft Dynamics CRM 4.0. The hotlist are one of the major component of Dynamics CRM, and it has some limitations in querying the information's required. Plug ins can be used to define the criteria and the use FetchXML query to get the information required.

Plug ins and IPluginExecutionContext

CRM SDK provides the list of Messages and entities which could be used for registering a plug in.

"Execute" is one of the Message type which could be used to register a plug in to trigger when an execute event is fired within CRM for a hotlist. The Execute message doesn't allow you to specify the primary or secondary entity, and will run within the logged in users context. There is Pre Stage and Post Stage stages for the pipeline execution and this could be used for both the Asynchronous and Synchronous execution modes.

The code below could be used to override the hotlist using the FetchXML and replacing it with the criteria required to return the exact result set. The
"context.InputParameters.Properties["FetchXml"]" gives you the currently executed query from CRM and this could be used if you just need to update the criteria only.

public class PeopleHotListViewsPlugin : IPlugin
public void Execute(IPluginExecutionContext context)
ICrmService vService = context.CreateCrmService(true);

if (context.InputParameters != null)
if (context.InputParameters.Properties.Contains("FetchXml"))

string fetch1 = @"
<fetch mapping='logical'>
<entity name='account'>
<attribute name='accountid'/>
<attribute name='name'/>
<link-entity name='systemuser' to='owninguser'>
<filter type='and'>
<condition attribute='lastname' operator='ne' value='Cannon' />

context.InputParameters.Properties["FetchXml"] = fetch1

The plug in should be registered using the Execute message as shown below.

The plug in will be executed each time a hotlist is called, but could be limited to the specific hotlist by matching the FetchXMl Entity node and adding a specific criteria to identify the hotlist.

Abish Asharaf

No comments: