, , ,

Hello Everyone,

In my Earlier post I have already written about registering the Plugin on QualifyLead message. But this time I had to register my plugin while Disqualifying a lead, but couldn’t found any message such DisQualifyLead in the msdn.

After reading some more I found that we have to use both the SetState message and the SetStateDyamicEntity message, to register a plugin while the state of an Entity changes.

  • There is also a slight change in the way of writing this plugin. Instead of ‘Target’ it is ‘Entity Moniker’ along with the State and Status Code.
 if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference)
                var myEntity = (EntityReference)context.InputParameters["EntityMoniker"];
                var state = (OptionSetValue)context.InputParameters["State"];
                var status = (OptionSetValue)context.InputParameters["Status"];

                if (myEntity.LogicalName == "lead" && state.Value == 2)
                   // Business Logic
  • In my business logic I had to find the related entity record from reference Entity and Deactivate that as well after the Lead Disqualifies.
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                        fetchXml += "<entity name='new_reference'>";
                        fetchXml += "<attribute name='new_referenceid' />";
                        fetchXml += "<filter type='and'>";
                        fetchXml += "<condition attribute='new_leadid' operator='eq' value='" + myEntity.Id + "' />";
                        fetchXml += "</filter>";
                        fetchXml += "</entity>";
                        fetchXml += "</fetch>";
                        var result = service.RetrieveMultiple(new FetchExpression(fetchXml));
                        if (result.Entities.Count > 0)
                            Guid ReferenceId = ((Guid)result.Entities[0].Attributes["new_referenceid"]);

                            SetStateRequest setStateRequest = new SetStateRequest()
                                EntityMoniker = new EntityReference { Id = ReferenceId, LogicalName = "new_reference" },
                                State = new OptionSetValue(1),
                                Status = new OptionSetValue(2)


Now we will register the plugin with the help of Plugin Registration Tool:

1>Select and Register New Plugin Assembly

2> Register New Step with SetState Message on Pre-Event Execution pipeline.

3> Again Register New Step bt this time with SetStateDynamicEntity Message on Pre-Event Execution pipeline.

4> Your Plugin Registration Tool will look like this in the fig. below:


Now the plugin will execute as expected after selecting the Disqualify option on Lead.

Hope this was informative.

Thanks !!!