I have implemented a plugin for my Dynamics CRM which is firing on Update message for incident entity. Also I have a web service for external users which can update just two attributes of incident entity from outside.
The problem is while external users use the web service to update entity, the plugin will fire also. I want to bind the plugin going to be fired just inside CRM when incident entity changed and prevent it firing by outside requests.
I checked below conditions in my plugin for preventing infinite loop and it works but not works for preventing firing by outside update requests.
if (context.Depth > 1 ||
context.Mode != 1 ||
context.MessageName != "Update" ||
context.IsolationMode != 1)
{
return;
}
To register plugin I've used the Plugin Registration Tool and I have set the step message to Update, and Run in User's Context as Calling User.
In my web service I've used Xrm.Sdk
and Xrm.Sdk.Client
to connect to CRM and update entity directly.
ColumnSet cs = new ColumnSet(new string[] {
"description", "statuscode"
});
Guid recordId = new Guid(caseID);
Entity currentRecord = crmService.Retrieve("incident", recordId, cs);
OptionSetValue osv = new OptionSetValue(1);
currentRecord["statuscode"] = osv;
currentRecord["new_answers"] = answer;
currentRecord["new_lastanswerdate"] = currentDate;
crmService.Update(currentRecord);
Anyone has any idea - How can I prevent plugin firing while an entity updated from outside of CRM?
InitiatingUserId
in the plugin execution context. With the Guid, you can check your user table and determine whether they are external or not – Chronicle