Create RITM from script - workflow initiations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2017 07:36 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2017 11:24 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2017 01:23 PM
Hi,
There is not special condition - the flow is related to a catalog item and stared after the catalog item is being submitted.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2017 05:59 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 01:18 AM
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