简体   繁体   中英

How to prevent firing Dynamics CRM Plugin execution while updating an entity using web service?

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?

The plugin executes in every server transaction & it gets triggered which is the expected behavior (that's the whole purpose).

You may use some other flag (additional attribute or any service account) which only get updated/used by outside integration, in that case you can check in execution context/target entity and ignore the further execution.

For external integration - you should create an Application user (non-interactive service account). Read more

I know it is a very old question, but there is a property of CrmServiceClient that allows you to bypass custom plugins from executing You can find more details here CrmServiceClient - BypassPluginExecution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM