Introduction:
Recently, we had a business requirement to make some fields, present in the Business process flow stage, to be required conditionally based on the value selected in one of the fields in the BPF stage.
First, we tried to achieve this by writing a client side JavaScript code to make the Business Process fields required based on the value selected in particular field.
But JavaScript won’t work! We tried to use ‘setRequiredLevel’, but this method doesn’t work for the fields present in the Business Process Flow even though we use ‘header_process_’ to get the fields.
Using the Branching functionality of Business Process Flow:
Finally, we decided to use the branching functionality of BPF which was introduced in Dynamics CRM 2015.
The logic is to have two stages with the same structure. The only difference would be that one stage will have the fields as required & another stage will have the fields as optional and switch these stages based on the value selected in the particular field.
We have a condition to check the value selected in field 1 of stage 1. If the field value is true then show Stage2 with Field 2 as required else show Stage 2 with Field 2 as optional, as seen in the image below;
Here, we have two stages for Stage 2. Everything will be a same, i.e., the name of the stage, number of fields, etc. except one will have the field as required and other will have the field as optional.
Below is the example of the Business Process flow designer where you can see that we are conditionally showing the same stages but with different field requirement levels.
To create the same stage we just copied the stage.
Note:
Each stage in the BPF has their own unique GUID. So in the above case where we have two same stages, the stage name would be the same, but the GUID of two stages would be different.
There is a ay to make normal approach work, you only need to set BPF field initally to not required and change it to required with javascript.
Maybe it will work for you also.
How could we set condition, if condition to check the value selected in field 1 of stage 2 instead of stage 1. If the field value is true then show Stage2 with Field 2 as required else show Stage 2 with Field 2 as optional?
As per my understanding, you want to check condition of first field and then set second field required based condition, both in same stage. However, in OOB, you cannot check condition and set field value in same stage.
You will get the below OOB error if you try to do the same:
So, in this case you will probably have to go custom coding way. For this, you can refer the following blog on how to write script on BPF:
https://www.inogic.com/blog/2015/08/applying-scripts-on-business-process-flow-controls-in-dynamics-crm-2015
Hope this helps.
Thanks!
Sorry, I’m new in business process and rules, but i wonder if it is possible to have a field mandatory only in a particular stage: now if I mark a field as mandatory and I set the step with this field in a particular stage the field is required independently of the current stage…
Hi Stefano,
Yes, it is possible to set the field mandatory in one stage and optional in another stage. For example, In the First Stage Purchase Timeframe field is optional (untick), which means you can move ahead to Stage 2 without filling it.
In Stage 2, the same field is set to be required. Now, you cannot finish the process without filling it.
Hope this helps
Thanks!