Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SetState Plugin Event does not fire in chained plugin execution

Posted on by Microsoft Employee

Hello,

I'm on Dynamics CRM 2016 SP1, and I ran into a strange issue yesterday that went against my understanding of plugins.

I have two plugins, they both fire on SetState/SetStateDynamicEntity. I'll call the first Plugin A, and the other Plugin B. They each trigger on a different entity type, which I'll also call Entity A, and Entity B.

The scenario I'm running into is that, if I deactivate Entity A, plugin A is supposed to find all Entity B records linked to A and then update their statecode to match what Entity A was set to and then that triggers additional logic in Plugin B

What I am finding however is that Plugin A updating Entity B statecodes never trigger Plugin B. If I deactivate Entity B directly, plugin B triggers. If I change my plugin steps on Plugin B to be Update (filtered to statecode attribute) then Plugin B triggers properly from Plugin A.

Is this behavior normal? Why would hooking the Update event instead of SetState be required to capture the change in statecode? Shouldn't changing the statecode via another plugin or directly on the reocrd always trigger the SetState/SetStateDynamic entity event?

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: SetState Plugin Event does not fire in chained plugin execution

    Hi AltDyn,

     if you do want to stick to SetStateDynamic, have a look here - that's, probably, where the problem is:

    blogs.msdn.microsoft.com/.../developing-plug-ins-for-crm-4-0

    community.dynamics.com/.../184070

    PS. Also, here is a post confirming that "Update" plugins have always been triggered for SetState requests (or, from my experience, that's how it has been in any version starting with Crm 2011):

    https://www.inogic.com/blog/2015/05/api-enhancement-service-update-message-in-crm-2015-update-1/

  • Suggested answer
    M I Mostafa Profile Picture
    M I Mostafa 4,257 on at
    RE: SetState Plugin Event does not fire in chained plugin execution

    Hi AltDyn,

    The standard depth is 8 as per the MSDN article however could it be that your on-premise Dynamics CRM server has maximum depth set at 2? I have seen this before. In all cases, the depth issue is something you have be careful with and manage / avoid carefully in your code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SetState Plugin Event does not fire in chained plugin execution

    Mohamed, with that explanation, why would triggering 1 other plugin exceed the max depth of 8? Wouldn't that be a depth of 2?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: SetState Plugin Event does not fire in chained plugin execution

    Hey AltDyn,

     actually, I've always been using "Update" plugins to capture state requests.. it works like a charm. What's even more interesting is that SetStateRequest is deprecated now:

    msdn.microsoft.com/.../microsoft.crm.sdk.messages.setstaterequest.aspx

     So.. it might just be the answer - start using update plugins instead:)

    PS. There was a thread recently discussing some issues with using "Update" request instead of SetState.. maybe not everything is that perfect yet. However, Update plugins definitely work.

  • Suggested answer
    M I Mostafa Profile Picture
    M I Mostafa 4,257 on at
    RE: SetState Plugin Event does not fire in chained plugin execution

    Yes. This behaviour is by design. This is because of the plugin execution depth is reached. This is used by the Dynamics platform for infinite loop prevention.

    Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the Depth property of the execution context is increased.

    If the depth property increments to its maximum value within the configured time limit, the platform considers this behavior an infinite loop and further plug-in or Workflow execution is aborted.

    The maximum depth (8) and time limit (one hour).

    This is configurable by the Microsoft Dynamics 365 (on-premise) administrator using the PowerShell command Set-CrmSetting. The setting is WorkflowSettings.MaxDepth.

    Have a look here:

    https://msdn.microsoft.com/en-gb/library/microsoft.xrm.sdk.iexecutioncontext.depth.aspx

    Please mark as "Verified Answer" if you found this response helpful.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans