Dynamic 365 SetStateDynamicEntity
I was working on a plugin that has to fire when record gets
deactivated or activated.
To handle this scenario I had to use SetStateDynamicEntity Message.
When it comes to the plug-in code you have to look for “EntityMoniker” as an
EntityReferece on the context. Here is a snippet of code:
if(context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference )
To retrieve the State and
Status values you can use the following code
OptionSetValue state = (OptionSetValue)context.InputParameters["State"];
OptionSetValue status = (OptionSetValue)context.InputParameters["Status"];
Here is where things got interesting, if you are like me you
are expecting the right value for the status “statucode
field value”, instead I started getting
Status=-1;
Which is not a valid value for the OptionSet field.
Which made me scratch my head and wonder what was happening.
I noticed few anomalies whenever I deactivate the record
with “Canceled” statuscode, status return
-1, whenever I deactivate the record with a different statuscode value status return the proper OptionSetValue, I noticed this behavior was not only limited to
deactivation of records it was even happening when I activated the record.
After investigating the OptionSet
fields I noticed that Canceled was the default value for Deactivation,
and whenever status code is set to the default value
(OptionSetValue)context.InputParameters["Status"]
always return -1.
I tested this scenario on multiple entities to my surprise
it was a consistent outcome.
So in conclusion whenever you deactivate or activate a
record if “statuscode” is set to
Default Value context.InputParameters["Status"]
will always return -1.
Comments
Post a Comment