I want to set the RITM Stage to "Request Cancelled" and State to "Cancelled" if the STASK is "Cancelled" or "Closed Incomplete".

Siva Kedari Vee
Mega Guru

Hi all,

I want to set the RITM Stage to "Request Cancelled" and State to "Cancelled" if the STASK state is "Cancelled" or "Closed Incomplete". because we don't include canceled tickets in our resolution reporting and this behavior is having a negative impact on our metrics (Because even if the catalog task is canceled or closed incomplete the RITM is setting to closed complete because we're setting the value for RITM stage and State as Completed in the workflow after the Catalog task). For most of our Catalog items, in the workflow after the catalog task completion we're setting the RITM stage "Completed" and state to "Closed Complete".

For a single item, I can edit the workflow but there is a number of items having the same issue. So i wrote a Business rule to Set the RITM Stage to "Request Cancelled" and State to "Cancelled" if the STASK state is "Cancelled" or "Closed Incomplete". 

But that didn't work, can anyone help me with this, why it didn't work.

I wrote this BR on sc_req_item table after insert or update

 Business Rule Condition: current.stage.changes() && (current.stage == 'complete')

Script:

updateRitm();

function updateRitm() {

if(current.sys_id == ' ')

return;

var task = new GlideRecord ('sc_task');

task.addQuery('request_item', current.sys_id);

task.query();

while(task.next()){

if(task.state == 'Closed Incomplete'){

current.stage = "Request Cancelled"; // Setting RITM Stage

current.state = "Closed Incomplete"; // Setting RITM State

} else if(task.state == 'Cancelled'){

current.stage = "Request Cancelled"; // Setting RITM Stage

current.state = "Cancelled"; // Setting RITM State

}

}

Please help me why my script is not working. Thanks in Advance.

Also i have another query that in workflow after setting the values of RITM(state and stage to complete) and then the workflow ends, if we make any changes to the RITM stages and state using any script will that change?

 

Thanks & Regards,

Sagar Sidagam.

 

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

Hi Sagar,

 

Instead of RITM you can write a Business rule on Catalog Task table when State changes to Cancelled or Closed incomplete with below snippet.

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

    // Add your code here
    var ritmis = new GlideRecord('sc_req_item');
    ritmis.query();
    while (ritmis.next()) {

        var taskis = new GlideRecord('sc_task');
        taskis.addQuery('request_item', ritmis.sys_id);
        taskis.query();
        while (taskis.next()) {
            if (taskis.state == 4) {//considering 4 is dictionary value for closed complete
                ritmis.stage = "Request Cancelled"; // Setting RITM Stage
                ritmis.state = 4; // Setting RITM State

            } else if (taskis.state == 5) //considering 5 is dictionary value for cancelled
            {
                ritmis.stage = "Request Cancelled"; // Setting RITM Stage
                ritmis.state = 5; // Setting RITM State
            }
        }
        ritmis.update();

    }
})(current, previous);

 

Tim Kulhavy
ServiceNow Employee
ServiceNow Employee

What's missing in your script is a "current.update()" call - however you should usually not do that in an after Business Rule (https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782).

I would recommend doing that change in a before Business Rule (in a before BR, also never use current.update(), your change is going to be saved without that here).