Workflow Process Corruption

When you have a workflow that is calling in a step a Custom Workflow Activity and you putting a workflow in draft, the Condition Expressions show as “Invalid Condition expression”. When you try to re-activate the workflow it isn’t possible because of the conditions.

This issue might appear if you changed the internal name of the input/output parameter and published the plugin. It will make the condition invalid because, the parameter that was used in the create/update step that is inside the condition is invalid, it is not recognizing the parameter. You need to remove the step and add it again.

Doing the deletion of the step and was able to change the condition branch and redo the Invalid condition expressions and after that, it was able to publish the workflow. Then added the step again. That way it was using the correct output parameter schema name.

Hope this helps.

Advertisements

Use Workflow to fill a field with the stage name

As you might know, in the Opportunity entity there was a field that saves the text of each stage, but if you want that for other entities that field might not be available.
There was a way that worked until the version 8.2, where you build a workflow to run in the entity that you have the BPF and then save the Process Stage Name to the field that you created.
In the new version that isn’t working very well, from my tests it is only saving the previous stage name (the stage that was before the active).
Now to have the actual stage I had to do like this:

-With the next BPF from 8.2, this isn’t working well since it is only putting in the field the previous stage.
-To achieve the what you want, you need to create a workflow that is running in the BPF entity of the process, for example, Phone to Case Process.
-Create a custom field to save the text.
-You put the workflow in sync, then select to run when “Process is applied” and “Process changes” then you select the field “Active Stage Id”
-Then you insert the step Update Record, change it to “Incident Id (Case)” in the workflow and in the properties you add to the field that you want to save the text of the process. On the right options Look for: Active Stage Id (Process Stage) and then the field Process Stage.

It should look like this:

Infinite loop on Plugin – Dynamics CRM

Have you ever had a situation where you want to use a plugin when a state of a record changes, and the logic needed to implement at the end of the code is to set that record again in the same state?

For instance, if you have a plugin registered in the Quote entity, message SetState/SetStateDynamicEntity and when you activate the Quote, the plugin starts. Your logic in the plugin says that is going to search for some records that are Active, put them in Draft state, changing the necessary fields and Activate it again.

What do we get? The infinite loop….

There is always a problem to these types of plugin, but sometimes you need to do it and how can you get around this problem? We can add a bool field, hidden in the form, to validate this operation at the begining of the plugin and when we first run the plugin, we change that field so the next time it tries to run, it will exit the execution.
It is just one more field, that is hidden in the form and maybe it is easier to manage (you need to remember that if is when you Activate, then when you Revise you need to revert the field), but sometimes there are so many fields that maybe it is better not to implement like that (and not so elegant).

There is another way to do this. You can build a plugin that can be used in a workflow (a workflow plugin), you have the same plugin logic implemented like you have in a normal plugin, but just need to change some of the execution steps of the plugin and how it is registered. If you use the Developer Toolkit for Visual Studio you can do it easily.

1-Create a Workflow Plugin class

Create Workflow Plugin

2-Add Input Parameters if necessary

Input Parameters
Next part of the plugin

3-Deploy your workflow plugin (if you are using Developer ToolKit, otherwise you register via PluginRegistrationTool)

Deploy Workflow Plugin

4-Create your workflow – This workflow can run on a changing of a field, changing of status, etc. In our case we had a button that called this workflow to Activate the Quote and then run my workflow plugin

Create Workflow.

5-Add the step to run your plugin

Choose the plugin

6-Choose the input – After you have added the step you can insert the input to the plugin

Step added
Input from fields

After this, everytime you can this plugin, automatic or via javascript it will run the plugin too.

If you want to just prevent that the plugin goes in an infite loop, you can use Deep property to check if already run.

if (context.Depth > 1) { return; }

Hope this helps.