setWorkflow(false) doesn't prevent the service catalog workflow from being triggered in my script

jammer
Tera Expert

I am working on a (background) script that will insert an RITM for a catalog item we already have built.  The catalog item has a workflow associated with it. 

The script works fine to create/insert the RITM, but it's triggering the workflow, which also means notifications (ex.  Request Opened on Behalf) are getting sent out.  I don't want the workflow to execute and I don't want those notifications being sent out.  I just want the RITM to be inserted via the script. 

I'm working in the global application scope and I tried using setWorkflow(false) and setUseEngines(false) to prevent the workflow from getting triggered, but that code isn't working as I had hoped.

Here is my script to insert the new RITM for this catalog item:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('e76e5c31dbf69740794ea951ca961627', 1);

//fill in the variables on the request item form
cart.setVariable(item,"assignment_group", "cb55d2854f121680ddf915924210c746"); 
cart.setVariable(item,"short_description", "Request server build");
var rc = cart.placeOrder();

var newRitmRec = new GlideRecord("sc_req_item");
newRitmRec.addQuery("request", rc.sys_id);
newRitmRec.query();
if(newRitmRec.next()){
    
     newRitmRec.short_description = 'Request server build';            
  newRitmRec.assignment_group = 'cb55d2854f2d16877df915924210c746';
  newRitmRec.setWorkflow(false);
    newRitmRec.setUseEngines(false);
    newRitmRec.update();
}

 

I found this related article (https://community.servicenow.com/community?id=community_question&sys_id=f5c4e8cedb1a7380190dfb2439961969) that suggests the setWorkflow(false) would prevent the workflow from executing for 'standard' catalog request items.

Is there a way to run my script so that it doesn't cause the workflow to trigger when the RITM is inserted?

3 REPLIES 3

Muhammad Khan
Mega Sage
Mega Sage

Yousaf
Giga Sage

Hi,

Please refer to these link. I hope this could help.

Cancel a workflow

Canceling executing workflows on task closure


Mark Correct or Helpful if it helps.



***Mark Correct or Helpful if it helps.***

-O-
Kilo Patron
Kilo Patron

The workflow is triggered as a result of executing

var rc = cart.placeOrder();

no way to stop it, if using the Cart API.