Process Step Settings: Rules

Rules are special conditions that prevent step from being proceeded.

Go to Process builder. Open Step Settings (1) and expand "Rules" (2).

Click on "add" link (3) to open popup (4).

General configurations of step rule are:

  • Name - used just for comfort and does not affect rule execution
  • Status - rules can be active (working) or inactive (e.g., temporary disabled).  
  • Error Message - user must enter the error message. It will be shown if the rule matches defined conditions (5).
  • Execute Before Step - if  checked, the rule will be automatically applied before step become active and, if rule matched, step will get status "Pending". Error message will be shown as Status Reason in the proper step tab (6).

Rule, if added, must have conditions configured and they must return boolean result (true or false).

Note: rule prevents step from further actions - an error message will be shown and step will not be proceeded when rule is matched (conditions return true).

Conditions can have different types:

  • Formula - logical expression with boolean result:
  • Query takes value from specified object field. If more then one record matches query conditions, the first value will be taken.

The difference between the Standard and Advanced mode is that the Standard option allows you to enter conditions based on the Data Source for this process, while the Advanced option allows you to select ANY available Data Source Object.

If there are more than one condition, user can configure their logic using the Index number of the conditions. E.g., if set {1} AND ({2} OR {3}) to make this rule work, condition 1 and one of conditions 2 or 3 must be true.

  • Flow Step Status simply checks defined step(s) for one or several statuses. User can select any step from any process:
  • Call Apex - executes specified Apex Class with given parameters and returns the result. Result should have boolean type.

Apex class used in rule validation should implement WR_BPM.WorkflowCallApexRuleInterface

If run method returns 'true' process will not move forward and error message configured in the action will be displayed.

The configuration in the example above will let process move forward if {$Variables.callType} = 'check A' AND {$Variables.A} is not blank or if {$Variables.callType} = 'check B' AND {$Variables.B} = 'BBB'. Otherwise custom error will show up.

Note: the Apex Class on example picture is made for test purposes. Here is the code example:

public with sharing class WR_ApexRulesExpample implements WR_BPM.WorkflowCallApexRuleInterface
{
    public static Boolean run(sObject context, WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor, String parameters)
    {
        Map<String, Object> params = (!String.isBlank(parameters) ? (Map<String, Object>)JSON.deserializeUntyped(parameters) : new Map <String, Object>());
   
        if(params.get('callType') == 'check A') 
        {
            if(String.isBlank((String)params.get('A')))
                return true;
            else 
                return false;
        }
        else if(params.get('callType') == 'check B' && params.get('B') == 'BBB')
            return false;
       
        return true;
    }
}

Save configured rule.

Rules will be shown in step properties. They can be deleted (7),  added to library (8), or edited by clicking rule name (9).

"Clone" button (11) will appear when the rule is being edited. After clicking it system will ask for cloned rule name and target step (12, mandatory).

After clicking "Apply" button an edit form for cloned rule will be shown.

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.