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

Mohith Devatte
Tera Sage
Tera Sage

hello @Snow Tomcal ,

try this in your script

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

    var ritm = new GlideRecord('sc_req_item');

    ritm.addQuery('number', 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

Still doesn't work, the state is still executing. But the error doesn't come up anymore.

@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

 

Thank you very much! It worked 🙂