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" />
</entity>
</fetch>
Run the fetchxml using XrmTollbox or just rebuild the
query in an Advance Find. After running the query you will notice there are
multiple versions that are in active state for the same workflow.
If you think about it
when you deactivate your workflow make changes and activate it back,
this action that you have performed is going to create a new version, and
remember the old version will still be sitting in active state.
So when you refer a workflow through its id in any of your
code, you are running the risk of calling an older version of your workflow.
So the best approach to this issue is:
1. Query
the workflow using its name
2. Sort
your query
3. Retrieve
the latest version of your workflow id
This will insure that you are calling the right version of
your workflow.
Comments
Post a Comment