Set Opportunity probability with Business Rules

As you might have noticed the opportunity entity has an out of the box field related to it that’s called ‘Probability’. This represents the opportunity’s probability of getting closed as a won deal. When you drag the field on the opportunity form there is no automatic calculation or anything for the values of this field. Users will have to manually enter a value in the probability field. In this article I am going to use business rules to automatically update the probability field with a value that is set based on the active stage in the associated business process flow. For example, if the opportunity business process is in the first stage ‘1-Qualify’ the probability will be set to 10%. If the opportunity is in the second stage ‘2-Develop’, the probability will be set to 25% and so on. I am also going to add the ability for users to turn off this automatic calculation of the probability field and to allow them to enter the probability manually.

Configuration

The first thing we need to do is add a field called ‘Manual Probability’. This field is a two options field and the values are ‘Yes’ and ‘No’. You can also enable field security on this field if you only want certain people to be able to turn this on or off. NOTE: If you turn on field security you will also have to create a field security profile where you give people access to this field.
Once the field is created it needs to be added to the opportunity form. Also make sure the probability field is present on the opportunity form. I placed the ‘Manual Probability’ field underneath the ‘Probability’ field on the form. You also need to drag the ‘Pipeline Phase’ field on the opportunity form as this field will also be used in the business rule.

Business Rules Configuration

In order to create a new business rule I navigate to https://make.powerapps.com/ and select the correct environment. Under ‘Data’ (left side) select ‘Entities’ and search for opportunity. Click on the ‘Business Rules’ tab on the top, then click ‘Add business rule’ on the command bar. This will open the business rule window. I entered ‘Set Opportunity Probability Field’ as the business rule name. Make sure you set the scope (this represents when/where you want to business rule to be active, in my case I set the scope to ‘All forms’. Please be advised that you will need to place all the fields you are referencing in the business rule on the form(s) for it to work.

In the first condition I have the following 2 rules:
Rule 1 – Source: Entity | Field: Pipeline Phase | Operator: Begins with | Type: Value | Value: 1

Rule 2 – Source: Entity | Field: Manual Probability | Operator: Does not equal | Type: Value | Value: Yes

Drag the ‘Set Field Value’ component next to the first condition (if true, represented by the check mark on the right side of the condition), then configure the component as follows: Field: Probability | Type: Value | Value: 10. The value represents the probability the opportunity has when the active state of the business process flow of the opportunity begins with the number 1. NOTE: You will need to configure your business process flows to include these numbers in the stages for this to work, or you can configure a different condition.
You can create as many conditions as you want, but in this example I created a total of 4 conditions:

Condition#2:
Rule 1 – Source: Entity | Field: Pipeline Phase | Operator: Begins with | Type: Value | Value: 2
Rule 2 – Source: Entity | Field: Manual Probability | Operator: Does not equal | Type: Value | Value: Yes

Condition#3:
Rule 1 – Source: Entity | Field: Pipeline Phase | Operator: Begins with | Type: Value | Value: 3
Rule 2 – Source: Entity | Field: Manual Probability | Operator: Does not equal | Type: Value | Value: Yes

Condition#4:
Rule 1 – Source: Entity | Field: Pipeline Phase | Operator: Begins with | Type: Value | Value: 4
Rule 2 – Source: Entity | Field: Manual Probability | Operator: Does not equal | Type: Value | Value: Yes

Drag the ‘Set Field Value’ component next to the newly created conditions (if true, represented by the check mark on the right side of the condition), then configure the component as follows: Field: Probability | Type: Value | Value: (this is the value you want to system to set in the probability field. In my example I set the 2nd condition to 25, the third to 50 and the fourth to 95 but it’s up to you. When your business rule is done, make sure to save is and activate it.

In order for users to manually set a probability, we need to create a second business rule. We want to lock the probability field when the ‘Manual Probability’ field is set to ‘No’ and we want to unlock the probability field when the ‘Manual Probability’ field is set to ‘Yes’. Click ‘Add business rule’ to create another business rule. I will call this business rule ‘Lock/Unlock Probability field’ so it’ll be easy to identify what exactly it does. You can also write a short explanation about what is does in the description field. The scope for this business rule is also set to ‘All forms’. Configure the condition as follows:

Rule – Source: Entity | Field: Manual Probability | Operator: Equals | Type: Value | Value: Yes

Drag the ‘Lock/Unlock’ component to the right side of the condition (if true, represented by the check mark on the right side of the condition), then configure the component as follows: Field: Probability | Status: Unlock |
Drag another ‘Lock/Unlock’ component next to the ‘if false’ condition (marked by the X meaning if the statement in the condition is false) then configure the component as follows: Field: Probability | Status: Lock |
Save the business rule and activate it. Now it’s time to test the configurations! I hope you enjoyed this post! Be sure to check in again next week for a new topic or subscribe here to never miss another post!

Share this!

Comments are Closed