RITM should reflect Closed Complete, Incomplete or Skipped depending on Task

mallikabhupathi
Tera Expert

Hi,

I have a requirement where the state of the RITM should be the same as the SCTask. When the SCTask is set to Closed incomplete, the RITM should show state as Closed Incomplete, if the SCTask is set to Closed Skipped, the RITM should show state as Closed Skipped, SCTask is set to Closed Complete, the RITM should show state as Closed Complete.

I have tried the workflow route and business rules route but nothing seems to be working.

Any help would be appreciated.

Thanks,

Mallika

1 ACCEPTED SOLUTION

Line number 10 is incorrect in your script. Please use the exact version of script as shared above. You don't need to hard code any sys id there.

Please use the exact script with no change required here.

Sharing it again for reference below:

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

	// Add your code here
	if(current.state.changes()){
		updateRITMState(current.request_item,current.state);
	}
	
	function updateRITMState(RitmID,state){
		var gr = new GlideRecord('sc_req_item');
		gr.addQuery('sys_id',RitmID);
		gr.query();
		if(gr.next()){
			gr.state = state;
			gr.update();
		}
	}
	

})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

6 REPLIES 6

Hi @shloke04 ,

 

That worked like a charm! 

 

Another question - can we use a similar script to show the state on the Request as Closed Complete, Closed Incomplete and Closed Skipped?

 

Thanks,

Mallika

Nope you need to update the same script as below:

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

    // Add your code here
    if (current.state == 2 || current.state == 3) {
        updateRITMState(current.request_item, current.state);
        updateRequestState(current.request_item.request, current.state);
    }

    function updateRITMState(RitmID, state) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', RitmID);
        gr.query();
        if (gr.next()) {
            gr.state = state;
            gr.update();
        }
    }

    function updateRequestState(requestID, state) {
        var gr = new GlideRecord('sc_request');
        gr.addQuery('sys_id', requestID);
        gr.query();
        if (gr.next()) {
            gr.state = state;
			gr.setWorkflow(false);
            gr.update();
        }
    }


})(current, previous);

This will ensure when ever you update a state of a catalog task the same will get updated both in Requested Item and Request form as well.

This is working fine for me in my PDI.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke