In this post I will show steps by steps how to implement plugin on Retrieve Multiple Message using the plug-in registration tool for Microsoft Dynamics CRM 2011
1. Step Create a new plugin
2. Add the following code snippets. Fieldname is the field that you want to check (example name of account).
// Comment
protected void ExecuteViewController(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = (IPluginExecutionContext)localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
if (qe.Criteria.Conditions != null)
{
ConditionExpression queryCondition = new ConditionExpression("fieldname", ConditionOperator.Equal, "value");
context.InputParameters["Query"] = qe;
}
}
3. Add plugin step (example: Account on entity)
4. If you want to add other steps you must repeat third step and you must register the associate event as below.
// Comment
public FilteredViewController()
: base(typeof(FilteredViewController))
{
base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "appointment", new Action(ExecuteFilteredViewController)));
base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "account", new Action(ExecuteFilteredViewController)));
base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "lead", new Action(ExecuteFilteredViewController)));
// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
}
Notes:
Previous code snippets (ExecuteViewController) can be used for each entities that contains the target field (fieldname).
Thanks,
Nicola Grillo