need to set ritm and req state based on sctask

Arjun Reddy Yer
Tera Guru

required help @Vasantharajan N @Ankur Bawiskar 

As I need to set the RITM & REQ state.

When the SCTASK state is "Closed Incomplete" then the RITM & REQ state needs to change to "Closed Incomplete".

Tried with below script in Business Rule.

 

Business Rule:

When : After (Update)

Table: sc_task

Script:

(function executeRule(current, previous /*null when async*/) {
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) //State is closed incomplete
        closedSCTask++;
}
if (closedSCTask == scTaskCount) {
    if (closedCompleteWOT > 0)
        closeRITM(3); // Set RITMstate = closed complete.
    else
        closeRITM(4); //Set RITM state = closed incomplete.
}
function closeRITM(state) {
    var msg = '';
    var ritmQuery = 'stateNOT IN3,4'; //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);
 

SCTASK State Value:

ArjunReddyYer_1-1717143381295.png

 

RITM State Value:

 

ArjunReddyYer_2-1717143428398.png

 

But when the SCTASK state is "Closed Complete" then the RITM & REQ state changes to "Closed Complete" via workflow it's working as expectecd.

1 ACCEPTED SOLUTION

Arjun Reddy Yer
Tera Guru

I got the solution after doing changes in workflow as well as UI Action 

 

Workflow:

 

ArjunReddyYer_0-1717150356245.png

UI Action:

 

ArjunReddyYer_1-1717150473031.png

ArjunReddyYer_3-1717150583277.png

 

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Arjun Reddy Yer 

did you check logs on what came in counter for closed and closed incomplete?

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

Arjun Reddy Yer
Tera Guru

I got the solution after doing changes in workflow as well as UI Action 

 

Workflow:

 

ArjunReddyYer_0-1717150356245.png

UI Action:

 

ArjunReddyYer_1-1717150473031.png

ArjunReddyYer_3-1717150583277.png