The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Create RITM from script - workflow initiations

Eli Guttman
Tera Guru

Hi,

i have a script that create RITM.

In that script, i'm creating Request (REQ), then creating requested item ( RITM), then adding the relevant variables and triggering the workflow withe the workflow startFlow function.

i have noticed that in this process, the requested item have 2 running workflows.

After investigating the issue, i have discovered the that the workflows are created in the points:

1. when is created the RITM

2, when i user the StartFlow function.

The flow that is created with i create the RITM does not take into account the variables, since the variables are not available on creation, only after.

My question is - how can i create the RITM without triggering the workflow.

this is the script for creating the RITM:

===========================================

  var elem = new GlideRecord("sc_req_item");

  elem.cat_item = cat_item;

  elem.request = idreq;

  elem.u_requested_for = caller_id;

  elem.quantity = 1;

  var id_reqitem = elem.insert();

  if (!elem.get(id_reqitem)) {

  return null;

  }

   

  return id_reqitem;

==========================================

Thanks in advance.

8 REPLIES 8

Nia McCash
Mega Sage
Mega Sage

What condition do you have in the Workflow properties ?   Could it be that the condition is triggering the Workflow and then you are additionally triggering it again when you do so from the script?


Hi,



There is not special condition - the flow is related to a catalog item and stared after the catalog item is being submitted.


sndangibbard
Mega Guru

You can prevent Business Rules and Workflows from being triggered by a GR insert/update with the GlideRecord method .setWorkflow(false)


This should be called before your .insert()



For example:


var elem = new GlideRecord("sc_req_item");


//..


elem.setWorkflow(false)


var id_reqitem = elem.insert();



Thanks


Dan


Julian Hoch
ServiceNow Employee
ServiceNow Employee

It's not recommended to create Requested Items via scripts. I recommend either using the Shopping Cart API to simulate putting an item into a shopping cart. See for example the following thread: Populate variables in cart api