Set Req state same as RITM state when the state changes in RITM with flow designer.

LakshmiNarayan7
Mega Guru

When the state field changes in RITM then, REQ state needs to be changed.

RITM States:                      REQ States :                        

 Open                                    Pending Approval.

 Closed Complete.                Approved, Closed Complete

 Closed Incomplete              Closed Incomplete, Closed Cancelled, Closed Rejected

 Closed Skipped                   Closed Skipped

 

For Approval the state changes works fine, But not for the rejection alone.

 

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Is Request and Requested Item always a one-to-one? If not, I think there is a better solution.

 

If it is a one-to-one your script works with a few tweaks:

Create an After Update Business rule on the Requested Item with following code:

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

    var request = new GlideRecord('sc_request');
    request.get(current.request)
    if (current.state == '3') {
        request.active = false; // set active to false
        request.request_state = '3'; // Set state to closed Complete
        request.update();
    }
    else if (current.state == '4') {
        request.active = false; // set active to false
        request.request_state = '4'; // Set state to closed Incomplete
        request.update();
    }

}

 

View solution in original post

10 REPLIES 10

Checked all the BR, Seems like there is something setting all the REQ to Approved.

Trying to write a BR for updating the REQ from RITM state changes.

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

//if (current.variables.select_one != 'Single CI Update')

var req = current.request;
var i = 0, j = 0, k = 0;
var appr, state;

var gr =new GlideRecord('sc_req_item');
gr.addQuery('request', req);
gr.query();
var count = gr.getRowCount();
while(gr.next())
{
if (gr.approval == 'approved')
{
i++;
}
if (gr.approval == 'rejected')
{
j++;
}
if (gr.approval == 'cancelled')
{
k++;
}
}
if (count == i && count!= 1)
{
RequestState('approved', 'closed_complete');
}

if (j == count-1 && count!= 1)
{
RequestState('rejected', 'closed_rejected');
}

if (k == count-2 && count != 2)
{
RequestState('Cancelled', 'closed_incomplete');
}


function RequestState(appr, state)
{
var gr1 = new GlideRecord('sc_request');
gr1.addQuery('sys_id', req);
gr1.query();
if (gr1.next())
{
gr1.approval = appr;
gr1.request_state = state;
gr1.update();
}
}

})(current, previous);

 

Approval and Rejection works fine, Need help on Cancelling.