How to set up complex conditions for business process flow ?

Business Process Flow (BPF) is a very useful tool to standardize data entry on a model driven app. In simple cases, a linear BPF is a good option. However, in more complex scenarios, a BPF can be enhanced by using branching. I will discuss on this blog the limitations and workarounds concerning branching conditions.

I was recently working on a business process flow and I noticed that once I use a condition with multiple rules, I could only use one of either operators: “AND” or “OR”. Moreover, I also noticed that it is not possible to define a branching rule using the type field “Multiselect OptionSet”.

Use case:

To illustrate these issues I will use the standard “Opportunity Sales Process” by adding a new phase named “Approve” where the user will go through this stage based on a given condition. This means that the user can go through the following two paths:

Path 1 (approval process)

Path 2 (without Approval process)

The Challenge

  • We will go through the “Approve” stage if and only if the condition below is true:
    (BUDGETAMOUNT >= 100000 OR (50000 <= BUDGETAMOUNT < 100000 AND (RISK = RISK 1 OR RISK = RISK 2))
  • Given that “Risks” is a “Multiselect OptionSet”
  • This kind of condition is not achievable using the Unified Process Designer.

Proposed solution

We will create a technical field (Yes/No) named “Need Approval” which will hold the result of (BUDGETAMOUNT >= 100000 OR (50000 <= BUDGETAMOUNT < 100000 AND (RISK = RISK 1 OR RISK = RISK 2)) which will be calculated using JavaScript Code.

After creating the Boolean field, we will add it to the BPF. The field must also be present on the previous stage. We will add it and make it read-only with a simple Business Rule.

1- Using the technical field in the branching condition

“Need Approval” field will be calculated by setNeedApproval function:

if (typeof (MEA) == "undefined") { MEA = {} };
if (typeof (MEA.Opportunity) == "undefined") { MEA.Opportunity = {} };
if (typeof (MEA.Opportunity.OpportunityForm) == "undefined") { MEA.Opportunity.OpportunityForm = {} };
MEA.Opportunity.OpportunityForm = {
onLoad: function (executionContext) {
var formContext = executionContext.getFormContext();
formContext.getAttribute('budgetamount').addOnChange(this.setNeedApproval);
formContext.getAttribute('mea_riskscode').addOnChange(this.setNeedApproval);
formContext.getControl('mea_isneedapproval').setDisabled(true);
},
setNeedApproval: function (executionContext) {
var formContext = executionContext.getFormContext();
var budgetamount = formContext.getAttribute("budgetamount").getValue();
var risks = formContext.getAttribute("mea_riskscode").getValue();
//(BUDGETAMOUNT >= 100000 OR (50000 <= BUDGETAMOUNT < 100000 AND (RISK = RISK 1 OR RISK = RISK 2))
if ((budgetamount >= 100000) || (budgetamount >= 50000 && budgetamount < 100000 && risks!=null && (risks.includes(278490000) || risks.includes(278490001)))){
formContext.getAttribute('mea_isneedapproval').setValue(true);
formContext.ui.process.reflow(true);
}
else{
formContext.getAttribute('mea_isneedapproval').setValue(false);
formContext.ui.process.reflow(true);
}
}
}

As you can see, I used the formContext.ui.process.reflow() method. Without the use of this method. The business process flow will not take into account the automatic change of the “Need Approval” field made by the JS code.

Advertisement

One thought on “How to set up complex conditions for business process flow ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s