How to make business rule run after flow state is completed

Community Alums
Not applicable

Hello Experts,

 

I have written a business rule to check whether all the tasks connected to RITM are closed complete or closed skipped.

The business rules is working fine when there is one task or multiple tasks getting triggered simultaneously, but the issue is when tasks triggered depending upon the closure of previous task, business rule does not wait. So, is there any method that can be used to make business rule wait until flow stage is completed and then run?

 

Business rule:

Tejas12_0-1724955988922.png

 

(function executeRule(current, previous /*null when async*/ ) {

    var grSCTask = new GlideRecord('sc_task');
    grSCTask.addQuery('request_item', current.getValue('request_item'));
    grSCTask.addActiveQuery(); // added to check for active tasks
    grSCTask.query();
    if (!grSCTask.hasNext()) // if there still are active SCtasks connected to this RITM, there is no need to set any state on the parent RITM yet
    {
        var closeCompleteCount = 0;
        var closeSkippedCount = 0;
        var closedOtherCount = 0;

        grSCTask = new GlideRecord('sc_task');
        grSCTask.addQuery('request_item', current.getValue('request_item'));
        grSCTask.query();
        var totalCount = grSCTask.getRowCount();
        while (grSCTask.next()) {
            if (grSCTask.getValue('state') == 3) {
                closeCompleteCount++;
            } else if (grSCTask.getValue('state') == 7) {
                closeSkippedCount++;
            } else {
                closedOtherCount++;
            }
        }

        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(current.getValue('request_item'))) {

            if (closeSkippedCount == totalCount) {
                ritm.setValue('state', 7); // ritm is closed skipped
                ritm.update();
            }
            else if (closeCompleteCount == totalCount) {
                ritm.setValue('state', 3); // ritm is closed complete
                ritm.update();
            }
            else if(closeCompleteCount+closeSkippedCount == totalCount) {
                ritm.setValue('state', 3); // ritm is closed complete
                ritm.update();
            }
        }
    }

})(current, previous);

 

5 REPLIES 5

Suresh K2
Tera Expert

Update filter condition state changes to closed complete or closed skipped and try. 

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums There is no way you can make a business rule wait. Instead if you are having a custom flow then either execute the script using a custom flow action which will execute this script. 

 

Community Alums
Not applicable

Hello @Sandeep Rajput ,

 

Thank you for your reply, I have never created a custom flow action, how the code will change and what input and output variables should be created?

 

Regards,

Tejas

StuartThoms
Tera Contributor

Without more information - the following alternatives may be better:

  • Business Rule on the flow context table - condition on state being complete and perhaps calling source being SERVICE_CATALOG
  • Business rule create a scheduled event which runs the script (make it run x time after the business rule runs)
  • Put the logic into the flows themselves