Skip to main content

Posts

Showing posts with the label Plugin

Why is it a bad idea to hardcode workflow id in your code?

You might have faced a scenario where you have to trigger workflows or an actions through plugins or JavaScript code. And you might have hard coded the workflow id in your code. There are few things that I would like you to reconsider before you get tempted to hardcode the workflow id in your code. Take a workflow name that you have been working lately and replace it on the following fetchxml. < fetch top = " 50 " >   < entity name = " workflow " >     < attribute name = " versionnumber " />     < attribute name = " name " />     < filter >       < condition attribute = " name " operator = " eq " value = " Workflow Name " />       < condition attribute = " statecode " operator = " eq " value = " 1 " />     </ filter >     < order attribute = " versionnumber " />   ...

Dynamic 365 SetStateDynamicEntity

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 ...