Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business Rule is impacting Catalog item workflow

SM123
Tera Expert

Hello, 

URGENT

we have a catalog item workflow which will automatically update REQ request state to "closed complete" and RITM state to "closed complete" and RITM stage to "complete" when i change Sc_task State "closed complete". (refer below pics).

As per new requirement when i change my sc_task state to "Pending Caller" OR " Pending Effective Date" atomatically my RITM state should change to "Pending". so, i wrote a business rule (refer below) to achieve this. My BR is working fine for when i choose my state as "Pending Effective Date" but when i choose "Pending caller" this business rule is also changing REQ request state to "closed complete", RITM stage to "complete" which should not happen. i couldn't able to debug why this is happening could some one help how to solve this?

(function executeRule(current, previous /*null when async*/) {
    // Get the parent RITM (Request Item) record
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.request_item)) {
        // Check if the RITM exists and its state is not already 'Pending'
        if (ritm.state != '-5') {
            ritm.state = '-5';
            ritm.update();
        }
    }
})(current, previous);

 

2 REPLIES 2

SM123
Tera Expert

Please ignore imgae(28) attachin correct imgae

 

Sandeep Rajput
Tera Patron
Tera Patron

@SM123 There is nothing wrong with your business rule. However, your workflow has issues as it creates the catalog task at step number 9 and without checking any conditions sets the RITM and Request to Closed Complete at step 10 and 11.

 

You might want to use a Wait for condition here to wait for the task to get closed complete before changing the RITM and Request states.

 

Please refer to the documentation here https://docs.servicenow.com/bundle/washingtondc-build-workflows/page/administer/flow-designer/refere... to know more about Wait for condition action.

 

Hope this helps.