This is very handy parameter of step registration process. It is equivalent to “IsDirty” function in JavaScript. If you use “Filtering Attributes” on post update events, you don’t need to compare the value of fields using PreEntityImage and PostEntityImage. The other biggest advantage is that your plugin does not execute on every update event.
Here is some code. This code creates a note for a contact when parentcustomerid field is updated.
protected void ExecutePostContactUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } // TODO: Implement your custom Plug-in business logic. IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; // 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 { Entity task = new Entity("task"); task["subject"] = "Account number is missing"; task["regardingobjectid"] = new EntityReference("contact", entity.Id); task["description"]= "Parent Customer field has been updated".; // Create the task in Microsoft Dynamics CRM. service.Create(task); } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex); } } }To run this code create a plugin using developer's toolkit on contact entity. Use the values shown in the screen shot to register the update step. Then overwrite the ExecutePostContactUpdate() method with this code. Deploy the plugin and test it.
Here is link to a step by step tutorial to create a plugin using developers toolkit.
Does anyone know if multiple attributes in the Filtering attribute are interpreted as OR or AND?
ReplyDeleteDoes anyone know if multiple attributes in the Filtering attribute are interpreted as OR or AND?
ReplyDeleteIt is interpreted as OR.
ReplyDelete