web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Difference between SetState & SetStateDynamicEntity

(1) ShareShare
ReportReport
Posted on by 1,067

Hi All,

I'm having a question regarding SetState & SetStateDynamicEntity mesagges, I've been searching on blogs but I don't really understand what's the difference. What I found is that if you register a plugin in SetState you have to also register another one in SetStateDynamicEntity. Another thing is that SetStateDynamicEntity uses EntityMoniker and SetStateRequest as a difference to normal plugins(Target & Service.Update), but what I would like to understand is why we have to register the plugin in both messages and which one will be called if in different scenarios(for example if I Activate an Account thorough the view or through the Form)

Thanks in advance.

Regards.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at

    They both do the same thing but diffrently

    There are multiple messages that perform the same action in CRM. One such example is SetStateRequest and SetStateDyanmicEntityRequest . If you want to write a plug-in on SetState, then you need to register it on both messages.

    Check the below post that explains this in detail..

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

    Even though it says crm 4.0 it applies to crm 2011/2013/2015.

  • Verified answer
    David Jennaway Profile Picture
    14,065 on at

    Unfortunately, there is no good reason for having 2 messages. My understanding is that SetStateDynamicEntity is only used for legacy code written for the CRM 4 endpoint; however some internal CRM functions used to use this.

    There is no definitive list of which actions cause which method, so the safest option is to jut register on both messages, and write the code to cope with the different sets of InputParameters

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi Crm user,

    I haven't confirmed this, but I was always told that SetState and SetStateDynamicEntity are different because one is run if you change the state through the CRM browser, while the other runs if you change the state through the SDK.

    Hope this helps! I'd appreciate if you'd mark any helpful answers as Verified.

    Thanks,

     Aiden

  • EnriqueMdz Profile Picture
    1,067 on at

    Thanks for your answer guys.

    Aiden, with SDK you mean Plugins/Code workflows?

  • EnriqueMdz Profile Picture
    1,067 on at

    Another question, SetState would be for browser and SetStateDynamicEntity for SDK?

  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    Yes, my understanding was that an SDK call using SetStateRequest would use one and clicking the Deactivate button in CRM would use the other. In either case you would want the same logic to run, so that's why you would register on both methods.

    Thanks,

     Aiden

  • Suggested answer
    amritesh Profile Picture
    362 on at

    Hi Aiden,

    I have registered a plugin on both SetState and SetStateDynamicEntity.

    But when I change the state through CRM browser or SDK, every time I found SetStateDynamicEntity message in the plugin, never got message

    SetState.

    Let me know if I am wrong.

  • Community Member Profile Picture
    on at

    Did you got any info.

  • Suggested answer
    Nishant Rana Profile Picture
    11,325 Microsoft Employee on at

    Yup it is always SetStateDynamicEntity either we do through browser or through SDK.  I was trying it for incident entity in Dynamics 365.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    I haven't use SetStateDynamicEntity & SetState and instead always preferred to write it for update message and use attribute filtering for statecode & statuscode field. I also ensure that the I have logic within the plugin code to return if the target entity doesn't contains the statecode & statuscode.

    ===========

     // Check we are in the process of completing

               // Status is not changing

               if (!entity.Attributes.Contains(phonecall.statuscode)) return;

               if (entity.ReadAttributeOptionSetValue(phonecall.statuscode, (int)decimal.Zero) != 2)

                   return;

    =====================

    Hope this helps.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans