locked
MS CRM 2011 - How to identify if the plugin is triggered from workflow in the plugin code? RRS feed

  • Question

  • Hi,

    I've a very basic question: is there a way by which we can identify in the plugin code that the plugin is triggered by the workflow?

    Early response is much appreciated.

    Thanks,
    Abhi
    Wednesday, June 26, 2013 7:11 AM

Answers

  • Hi Yatin,

    Yes. The approach mentioned above will work correctly but I was looking for the solution in code so that it will not introduce new field addition on the entity. And finally I got an solution for this.

    This is how it works:

    Though 'CallerOrigin' property is deprecated in CRM 2011, we can check to see the origin of the plugin (which doesn't actually work on 'Online' deployments) by using this code:

    context.GetType().GetProperty("CallerOrigin").GetValue(context, null).GetType().Name

    which will return values like: 

    ApplicationOrigin / AsyncServiceOrigin / WebServiceApiOrigin

    So, this way, it solved the issue I was facing.
    Hope this helps!

    Thanks,
    Abhi

    • Marked as answer by Abhi D Wednesday, June 26, 2013 8:20 AM
    Wednesday, June 26, 2013 8:19 AM

All replies

  • Create a custom attribute (just to track plugin is being triggered from workflow update action).

    Update value of this custom attribute in workflow.

    Register plugin step for that entity on update of that custom attribute (using Filtering Attributes on plugin registration tool).

                                                                             OR 

    If you already have registered update step, then in code you can check the value of this attribute and can make the decision whether it has been triggered due to workflow action.

    You may consider resetting value of custom attribute, so next time when workflow runs on same record should able to update value. I may consider bool type custom attribute in such scenario.

    • Proposed as answer by Yatin Babaria Wednesday, June 26, 2013 7:49 AM
    Wednesday, June 26, 2013 7:48 AM
  • Hi Yatin,

    Yes. The approach mentioned above will work correctly but I was looking for the solution in code so that it will not introduce new field addition on the entity. And finally I got an solution for this.

    This is how it works:

    Though 'CallerOrigin' property is deprecated in CRM 2011, we can check to see the origin of the plugin (which doesn't actually work on 'Online' deployments) by using this code:

    context.GetType().GetProperty("CallerOrigin").GetValue(context, null).GetType().Name

    which will return values like: 

    ApplicationOrigin / AsyncServiceOrigin / WebServiceApiOrigin

    So, this way, it solved the issue I was facing.
    Hope this helps!

    Thanks,
    Abhi

    • Marked as answer by Abhi D Wednesday, June 26, 2013 8:20 AM
    Wednesday, June 26, 2013 8:19 AM