I want set RITM state based on the catalog task state. If catalog task state is Close complete. then RITM state also should change close complete. how i can do it.?

Mannam Praveen
Tera Expert

I want set RITM state based on the catalog task state. If catalog task state is Close complete. then RITM state  also should change close complete. how i can do it.? 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hey,

You need to have a logic which will check all catalog tasks closed, before it goes ahead and close the RITM.

Table - Catalog Task(sc_task)

After - Update - State changed to Closed Complete.

How this BR runs, if your catalog tasks are closed, it will close the RITM, if your catalog tasks are incomplete or canceled, it will set the RITM as same.

 

var requestItem = current.getValue('request_item');

    var closedCompleteSCTask = 0;
    var closedSCTask = 0;

    var scTask = new GlideRecord("sc_task");
    scTask.addQuery("request_item", requestItem);
    scTask.query();
    var scTaskCount = scTask.getRowCount();
    while(scTask.next()) {
        var scTaskState = scTask.getValue('state');
        if (scTaskState == 3) { // State is closed complete		
            closedCompleteSCTask++;
            closedSCTask++;
        }
        if (scTaskState == 4 || scTaskState == 7) //State is closed incomplete or closed skipped
            closedSCTask++;
    }
    if (closedSCTask == scTaskCount) {
        if (closedCompleteWOT > 0)
            closeRITM(3); // Set RITMstate = closed complete.
        else
            closeRITM(7); //Set RITM state = closed cancelled.
    }

    function closeRITM(state) {
        var msg = '';
        var ritmQuery= 'stateNOT IN3,4,7'; //State is not one of the Closed states
        var requestItem= new GlideRecord('sc_req_item');
        requestItem.addEncodedQuery(ritmQuery);
        requestItem.addQuery('sys_id', wo);
	requestItem.query();
        if (requestItem.next()) {
            requestItem.setValue('close_notes', msg);
	    requestItem.setValue('state', state);
            requestItem.update();
        }

    }
})(current, previous);

 

Best Regards
Aman Kumar

View solution in original post

7 REPLIES 7

Hi,

did you try to debug that BR?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Aman Kumar S
Kilo Patron

Hey,

You need to have a logic which will check all catalog tasks closed, before it goes ahead and close the RITM.

Table - Catalog Task(sc_task)

After - Update - State changed to Closed Complete.

How this BR runs, if your catalog tasks are closed, it will close the RITM, if your catalog tasks are incomplete or canceled, it will set the RITM as same.

 

var requestItem = current.getValue('request_item');

    var closedCompleteSCTask = 0;
    var closedSCTask = 0;

    var scTask = new GlideRecord("sc_task");
    scTask.addQuery("request_item", requestItem);
    scTask.query();
    var scTaskCount = scTask.getRowCount();
    while(scTask.next()) {
        var scTaskState = scTask.getValue('state');
        if (scTaskState == 3) { // State is closed complete		
            closedCompleteSCTask++;
            closedSCTask++;
        }
        if (scTaskState == 4 || scTaskState == 7) //State is closed incomplete or closed skipped
            closedSCTask++;
    }
    if (closedSCTask == scTaskCount) {
        if (closedCompleteWOT > 0)
            closeRITM(3); // Set RITMstate = closed complete.
        else
            closeRITM(7); //Set RITM state = closed cancelled.
    }

    function closeRITM(state) {
        var msg = '';
        var ritmQuery= 'stateNOT IN3,4,7'; //State is not one of the Closed states
        var requestItem= new GlideRecord('sc_req_item');
        requestItem.addEncodedQuery(ritmQuery);
        requestItem.addQuery('sys_id', wo);
	requestItem.query();
        if (requestItem.next()) {
            requestItem.setValue('close_notes', msg);
	    requestItem.setValue('state', state);
            requestItem.update();
        }

    }
})(current, previous);

 

Best Regards
Aman Kumar

Hi @Aman Kumar S ,

    Can you please explain where is this variable defined in this line(if (closedCompleteWOT > 0) - "closedCompleteWOT ")

and what is this variable defined in this line (
requestItem.addQuery('sys_id', wo); - "wo")

 

Regards,

Shalani R