Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Cancel workflow using RITM

Snow Tomcal
Tera Expert

Hi, I am trying to create a business rule that is triggered when a field is changed in a certain table. 

The business rule is supposed to cancel the workflow running on a specific request that uses the record. 

So the "current" is the record in the table which field I changed. The record also has a reference field to the RITM, so I tried to use it and stop the workflow running from the RITM. I get the error "input argument to Workflow Script API is not valid GlideRecord. Creating default current". 

Adding my script: 

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

    var ritm = new GlideRecord('sc_req_item');

    ritm.addQuery('number', current.u_request_number);

    ritm.query();

    

    var workflow = new Workflow();

    workflow.cancel(ritm);

})(current, previous)

 

also tried canceling the context, also gave me the same error.

Anyone have any ideas? Thanks! 🙂

1 ACCEPTED SOLUTION

@Snow Tomcal i think i got the issue we are comparing with number but we need to compare with sys_id as you are storing the RITM in the reference field so try this below script

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

    var ritm = new GlideRecord('sc_req_item');

    ritm.addQuery('sys_id', current.u_request_number);

    ritm.query();
if(ritm.next())
{
    

    var workflow = new global.Workflow();

    workflow.cancel(ritm);
}

})(current, previous)

Hope this helps 

Mark the answer correct if this helps you

 

View solution in original post

5 REPLIES 5

Ashish21
Giga Expert

Hi,

 

Please find below hyperlink:

https://community.servicenow.com/community?id=community_question&sys_id=a57a47e9db5cdbc01dcaf3231f9619b8

 

Please mark this correct or helpful.

 

Thanks,