What are Partial Merges in Business Process Flow (BPF), and what can we do about it – Dataverse / Dynamics 365


Let’s take an example.

Suppose we have the following Business Process Flow (BPF) for Leads:

If the Lead Type = Grade A, we want the Grade A Details stage to appear. For other grades (B, C, D), we skip that stage and continue. So far, this is simple.

A screenshot of a computer

AI-generated content may be incorrect.

Now, say we have a new business requirement :

For Grade D, the process should only have the Initial Review and its own Closed stage. For Grades B and C, the process should follow Other Details + Closed.

To handle this, we added a condition:

If Lead Type = B or C → go to Other Details

Else (Grade D) → go directly to Grade D (Closed)

A computer screen shot of a computer

AI-generated content may be incorrect.

However, when we try to connect the B/C path to Other Details, the D path (Closed) also gets merged into it.

A screenshot of a computer
AI-generated content may be incorrect.
This is because of the way branching works in BPF.

Dataverse does not support “partial merges.” That means we can’t end one branch early and merge another branch later. If we merge one branch, Dataverse forces all branches to merge into the same stage.

A screenshot of a computer

AI-generated content may be incorrect.

One Branch Ends, One Branch Merges (Not Supported) – If we try to design a BPF where one branch terminates in its own last stage while the other continues and merges into a later stage, the platform will not allow it.

There are two ways to solve this:

Option 1: Repeat the stages : Instead of trying to merge one path and end another, duplicate the stages where needed.

For example, create a separate Other Details and Closed stage for Grades B and C.

A computer screen shot of a computer

AI-generated content may be incorrect.

Option 2: Simplify with fields / scripts

If we don’t want to repeat too many stages, we can:

Move the Lead Type field and Grade A Details fields into the Initial Review stage. Use business rules or form logic to show/hide those fields based on Lead Type. Delete the extra Grade A Details stage.

Update the condition so that the flow only needs one condition (A/B/C vs D).

A computer screen shot of a computer screen

AI-generated content may be incorrect.

Key Takeaway –

In Dataverse BPF:

One branch ending while another merges is not supported.

Either all branches merge or each branch must have its own end stage.

The solution is to repeat stages where needed, or simplify the design using fields and conditions.

Hope it helps..

Advertisements

Boolean Fields in Business Process Flows: Required Field Behavior Explained (Dataverse / Dynamics 365)


When designing Business Process Flows (BPF) in Dataverse, we often want to make certain fields mandatory before users can move to the next stage. A common scenario is using a Boolean (Two-Option) field — for example, Approved? with values Yes and No.

At first glance, it seems natural to mark this field as required in the BPF stage. But here’s the catch:

If the user selects Yes, the BPF allows stage progression.

If the user selects No, the BPF still blocks progression.

This can be confusing, because technically a Boolean field is never empty — it always holds a value. So why is “No” being treated as invalid?

This happens because Dataverse handles Boolean fields differently inside BPF compared to regular forms. In a BPF, when a Boolean field is set as Required, the platform interprets only Yes (true) as a valid value. A No selection is treated as if the field is still unset. This is a limitation in how BPF validations work.

A close-up of a purple card

AI-generated content may be incorrect.
A close-up of a purple box

AI-generated content may be incorrect.

Below we have 2 approved fields, one is of type Boolean and the other of type Choice. We can see that on clicking on the Next button, although we have provided the value No to both these fields, it is still expecting a value for the boolean field.

Here we can solve it 2 ways, as shown above, we can create and use a Choice field instead of a Boolean field.

Or instead of making the Boolean field as required in the BPF, we enforce the rule using JavaScript (addOnPreStageChange).

Boolean fields in BPF don’t behave the same way as in forms. When set to required, only Yes is treated as valid, while No is ignored. The simplest and most reliable solution is to replace Boolean fields with a two-value Choice field when they need to be required in a BPF. This ensures both Yes and No are considered valid, and users won’t be blocked unnecessarily.

Hope it helps..

Advertisements

Update Business Process Flow Stage using Excel Import with Power Automate – Dataverse / Dynamics 365


In some business scenarios, we might need to update the Business Process Flow (BPF) stage of a record during an Excel import — especially during data migration or bulk record manipulation. In this blog post, we’ll walk through how to set a desired BPF stage (based on the stage name) and automatically move the record to that stage using Power Automate.

We’re working with a custom Dataverse table called Test(cr1a7_test) and a Business Process Flow named My Business Process Flow, which includes the following stages:

“select processidname,stagename, processstageid from processstage where processid = [processGUID]”

A screenshot of a computer

AI-generated content may be incorrect.

Our goal is to allow users to specify the stage name (e.g., “Stage 2”) through Excel import, and have a Power Automate flow update the record’s BPF instance to the corresponding stage automatically.

For this –

  • We’ll add a field called the Desired BPF Stage choice field on our table to store the desired stage name.
  • We’ll create a Power Automate flow that triggers on create or update.
  • We’ll maintain a static JSON mapping of stage names to stage IDs and their traversed paths.
  • We’ll look up the corresponding stage ID and traversed path from the JSON.
  • We’ll fetch the BPF instance for the record.
  • We’ll update the BPF instance with the new active stage and traversed path.

Below is how we can define our JSON structure for mapping, which we will store either in a variable inside Power Automate or save as an environment variable.

A computer code on a white background

AI-generated content may be incorrect.

Trigger – When a row is added or modified.

A screenshot of a computer

AI-generated content may be incorrect.

Initialize Variable with JSON mapping

A screenshot of a computer

AI-generated content may be incorrect.

Parse JSON – using the sample data

A screenshot of a computer

AI-generated content may be incorrect.

Use a “Filter array” action to find the object where stageName matches custom_desiredbpfstage.

A screenshot of a computer

AI-generated content may be incorrect.

Initialize variables to store the Stage ID and traversed path.

  • first(body(‘Filter_array’))?[‘stageId’]
  • first(body(‘Filter_array’))?[‘traversedPath’]
A screenshot of a computer

AI-generated content may be incorrect.

Use List Rows to check if BPF Instance exists or not, if not we will create it or update it.

  • length(outputs(‘List_rows’)?[‘body/value’]) > 0
A screenshot of a computer

AI-generated content may be incorrect.

Update or Create a new BPF instance associated with the record.

A screenshot of a computer

AI-generated content may be incorrect.

Below we can see the user specifying the Stage 3 value for the Desired BPF Stage column in the Excel to be imported.

A screenshot of a computer

AI-generated content may be incorrect.

We can see the Excel imported successfully.

A screenshot of a computer

AI-generated content may be incorrect.

Below we can see our flow running successfully.

A screenshot of a computer

AI-generated content may be incorrect.

And the record in Stage 3 of the BPF.

A screenshot of a computer

AI-generated content may be incorrect.

Hope it helps..

Advertisements

Customizing Business Process Flows: Stage Validation Using JavaScript (Dynamics 365 / Dataverse)


Business Process Flows (BPF) in Dynamics 365 offer a structured way to guide users through a defined process. However, there are scenarios where progression to the next stage must be validated against specific business rules. In this blog, we see how to implement custom validations on stage progression using JavaScript.

Let us take a simple scenario where a Lead can only progress to the next stage of a BPF if

Lead Quality = Hot and Lead Source = Web

If these conditions are not met, users will receive a notification, and the stage change will be prevented.

Below is the sample code


function OnLoad(executionContext)
{
 var formContext = executionContext.getFormContext();
 formContext.data.process.addOnPreStageChange(validateStageProgression);
}


function validateStageProgression(executionContext)
{
	    var bpfSampleStage = "6e2b5d9e-da30-4a47-8ca9-d75c24fd51f4";
        var formContext = executionContext.getFormContext();
		var rating = formContext.getControl('header_process_leadqualitycode').getAttribute().getValue();
		var leadSource = formContext.getControl('header_process_leadsourcecode').getAttribute().getValue();
		var stageObj = formContext.data.process.getActiveStage();
        var stageId = stageObj.getId();
		var requiredFieldErrorId = "contractValidationNotificationId";
        formContext.ui.clearFormNotification(requiredFieldErrorId);
		
		if(stageId)
		{
			 if (stageId.toLowerCase() === bpfSampleStage)
			 {
				  if (executionContext.getEventArgs().getDirection() === "Next") 				  
				{
                    executionContext.getEventArgs().preventDefault();
					if(rating == 1 && leadSource == 8) // rating = Hot and Source = Web
					{
						formContext.data.process.removeOnPreStageChange(validateStageProgression);
                        formContext.data.process.moveNext();
					}	
					else
					{
						notificationMessage = "Cannot move to the next stage until conditions are met !";
						formContext.ui.setFormNotification(notificationMessage, "ERROR", requiredFieldErrorId)
					}
				}
			 }
		}
}

The addOnPreStageChange method registers the validation function on the form’s load event to monitor stage changes.

The preventDefault() method stops the stage transition if the conditions are not met, ensuring data integrity.

If the validation fails, an error notification is displayed using the setFormNotification() method, guiding users to correct the data.

Upon satisfying the conditions, moveNext() is invoked programmatically to move the process to the next stage.

As shown below, clicking on Next as rating and lead source values do not satisfy the condition, we can see the notification on the form and the user is not able to move to the next stage.

Also check – https://nishantrana.me/2024/10/09/use-javascript-to-enable-a-field-only-if-the-stage-is-active-in-business-process-flow-dynamics-365-dataverse/

https://nishantrana.me/2024/10/10/use-javascript-to-add-onchange-event-to-a-field-in-the-business-process-flow/

https://nishantrana.me/2024/10/23/javascript-for-fields-in-business-process-flow-few-key-points-dataverse-dynamics-365/

Hope it helps..

Advertisements

JavaScript for fields in Business Process Flow (few key points)– Dataverse / Dynamics 365


Suppose we have the following fields in the form as well as in the business process flow stage for the lead.

  • Rating and Email in the form.
  • Rating 1, Rating 2, and Email in the BPF.
A screenshot of a computer

Description automatically generated

And let us apply the below JavaScript on the form load.

A screenshot of a computer code
Description automatically generated

On opening the lead form below is the result we get.

formContext. getControl(“leadqualitycode”).setVisible(true);

Sets the Rating field visible on the form.

formContext. getControl(“header_process_leadqualitycode”).setVisible(false);

Hides the Rating 1 field on the BPF.

formContext.getControl(“header_process_leadqualitycode_1”).setVisible(true);

Set the Rating 2 field visible on the BPF.

As the getControl method is used to show or hide the field it only applies to the field being referenced. That is why we only have the Rating 1 field on the BPF being hidden.

formContext. getAttribute(“leadqualitycode”).setRequiredLevel(“required”);

Set the Rating field on the form as mandatory.

formContext.getControl(“header_process_leadqualitycode_1”). getAttribute().setRequiredLevel(“none”);

Set the Rating 2 field in BPF as non-mandatory

We are setting the Rating field on the form as mandatory, in the next line we are setting the Rating 2 field on the BPF as non-mandatory, the final result is Rating field is non-mandatory on the form as well because here getAttribute method is used which applies to the attribute level so gets applied to all its corresponding controls.

formContext.getAttribute(“leadqualitycode”).setValue(3)

Set the Rating field on the form’s value to Cold

As getAttribute is being used the value set for the Rating field on the form applies to the field in the BPF also.

formContext. getControl(“header_process_leadqualitycode_1”).setDisabled(true);

Set the Rating 2 BPF field as disabled.

As getControl is used it only applies/disables the Rating 2 field on the BPF.

formContext.getControl(“header_process_emailaddress1”). getAttribute().setValue(“test@test.hotmail.com”);

Set the value of the Email address field on the form.

As getAttribute is being used the value set for the Email field on the BPF also applies to the field on the form.

formContext.getControl(“header_process_leadqualitycode_1”). getAttribute().addOnChange(function () { var lastNameValue = formContext.getAttribute(“lastname”).getValue(); if (lastNameValue) { alert(“Hello, ” + lastNameValue + “!”); } else { alert(“Hello World!”); } });

Adds the on-change event to the Rating 2 field on the BPF.

As getAttribute is being used the on-change event handler is applied to both the fields on the form as well as field.

Check other posts on BPF –

https://nishantrana.me/2024/10/09/use-javascript-to-enable-a-field-only-if-the-stage-is-active-in-business-process-flow-dynamics-365-dataverse/

https://nishantrana.me/2024/10/10/use-javascript-to-add-onchange-event-to-a-field-in-the-business-process-flow/

Hope it helps..

Advertisements

Use JavaScript to add onchange event to a field in the Business Process Flow


Let us continue our previous post, here we will update the script to add an onchange event to the Identify Sales Team field in the Business Process Flow. Based on the value selected we will make the Develop Proposal field mandatory.

A screenshot of a computer

Description automatically generated

Below is the code we need to add for it.

A screen shot of a computer program

Description automatically generated
function OnLoad(executionContext)
{
	 var formContext = executionContext.getFormContext();
	 formContext.data.process.addOnStageChange(CheckStageAndToggleFieldBPF);
	 CheckStageAndToggleFieldBPF(executionContext);
}

 function CheckStageAndToggleFieldBPF(executionContext) {

        var formContext = executionContext.getFormContext();     
        var activeStage = formContext.data.process.getActiveStage();
        var activeStageId = activeStage.getId();		
        var stagePropose = "3a275c22-fc45-4e89-97fc-41e5ec578743";
     
        if (activeStageId.toLowerCase() === stagePropose) {          
                formContext.getControl("header_process_identifypursuitteam").setDisabled(false);                 
        }
        else {
            formContext.getControl("header_process_identifypursuitteam").setDisabled(true);
        }    

		formContext.getControl("header_process_identifypursuitteam").getAttribute().addOnChange(function(executionContext) {

                if (formContext.getControl("header_process_identifypursuitteam").getAttribute().getValue()) 
				{
                    formContext.getControl("header_process_developproposal").getAttribute().setRequiredLevel("required");
                }
                else 
				{
                    formContext.getControl("header_process_developproposal").getAttribute().setRequiredLevel("none");
                }
            });
  }
  
  
  
  

We can add it to the field if it is in the form also, that will also work the same. However, if we do not have the field on the form we need to add it to the field on the BPF.

On selecting the value completed for Identify Sales Team, we can see the Develop Proposal field being set as mandatory.

A screenshot of a computer

Description automatically generated
A screenshot of a computer

Description automatically generated

Later if we add the same field on the form, or into another stage of the BPF, the onchange event will apply and work for them.

For the field on the form –

A screenshot of a computer

Description automatically generated

Same field in another stage –

A screenshot of a computer

Description automatically generated
A screenshot of a computer screen

Description automatically generated

Hope it helps..

Advertisements