SBX - Search With Button

SBX - Forum Post Title

Difference between SetState & SetStateDynamicEntity

Microsoft Dynamics CRM Forum

Enrique asked a question on 7 Dec 2015 11:24 AM
My Badges

Question Status

Verified

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.

Reply
Chitrarasan Duraisamy responded on 7 Dec 2015 11:37 AM
My Badges
Verified Answer

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.

Reply
David Jennaway responded on 7 Dec 2015 11:47 AM
My Badges
Verified Answer

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

Reply
Aiden Kaskela (MVP) responded on 7 Dec 2015 12:06 PM
My Badges
Suggested Answer

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

Reply
Enrique responded on 7 Dec 2015 12:10 PM
My Badges

Thanks for your answer guys.

Aiden, with SDK you mean Plugins/Code workflows?

Reply
Enrique responded on 7 Dec 2015 12:11 PM
My Badges

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

Reply
Aiden Kaskela (MVP) responded on 7 Dec 2015 12:15 PM
My Badges
Verified Answer

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

Reply
A Singh responded on 7 Mar 2017 4:05 AM
My Badges
Suggested Answer

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.

Reply
Vickram Rathood responded on 5 Dec 2017 5:31 AM

Did you got any info.

Reply
Suggested Answer

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

Reply
Ravi Kashyap responded on 11 Jul 2018 4:24 AM
My Badges
Suggested Answer

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.

Reply
Chitrarasan Duraisamy responded on 7 Dec 2015 11:37 AM
My Badges
Verified Answer

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.

Reply
David Jennaway responded on 7 Dec 2015 11:47 AM
My Badges
Verified Answer

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

Reply
Aiden Kaskela (MVP) responded on 7 Dec 2015 12:15 PM
My Badges
Verified Answer

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

Reply
Aiden Kaskela (MVP) responded on 7 Dec 2015 12:06 PM
My Badges
Suggested Answer

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

Reply
A Singh responded on 7 Mar 2017 4:05 AM
My Badges
Suggested Answer

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.

Reply
Suggested Answer

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

Reply
Ravi Kashyap responded on 11 Jul 2018 4:24 AM
My Badges
Suggested Answer

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.

Reply

SBX - Two Col Forum

SBX - Migrated JS