Trigger Workflow Based on Catalog Item Selection in Order Guide

jmiskey
Kilo Sage

I have kind of a tricky situation which I am trying to figure out how to approach.

We have an Order Guide with three Catalog Items to choose from.  The Order Guide itself does not have a workflow attached to it.  2 of the 3 Catalog Items in my Order Guide do.  They are pretty straight forward, creating a single RITM, so those Workflows run off of sc_req_item and are available to be selected from the Workflow field on the Catalog Item.

However, my third one is a bit trickier.  It needs to create multiple RITMs, so the Workflow needs to run against sc_request so we can create multiple RITMs within that workflow.  However, when we create a workflow based on sc_request, it is not available to be selected from the Workflow field on the Catalog Item.  

I see from Workflow -> Properties -> Conditions, I could try to set a condition of which the workflow should run.  We have done this before, based on the Order Guide value.  However, that Order Guide was pretty straight forward and didn't have three different Catalog Items, each with their own workflow, listed underneath it.  So the Order Guide field,in and of itself, does not contain enough information regarding when the workflow should be called.  It is dependent upon the Catalog Item selected in the Order Guide (have a variable for that selection).

So, how can I do this?  How can I set up the Workflow for this third option to run off of sc_request and get it to be called when that third option is selected?

Thanks

1 ACCEPTED SOLUTION

This is what I have used to trigger new items from an initial item and added to the same request.

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request,<sysID of the item>, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);

My use case:

We had an item that collected multiple share file locations, but needed individual approvals for each location.  My setup was an initial item that runs a script with this code in it to generate the individual items under the same REQ.  The original item closes automatically after the fact, so one 'item' spawns x number of individual items (dependent upon how many share file locations they request), all on the same REQ.

 

https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=GlideappCalcHelperAPI

View solution in original post

35 REPLIES 35

shill
Mega Sage

From what you describe, your workflow creates the additional scripted RITM's?  Is there anything else happening in that workflow other than the item generation?

My thought is instead of using a workflow on the REQ, to create a record producer and include the generation script in that producer with an abort call in the record producer script (so you are not actually creating a record anywhere, but just running the script).

Granted, this all depends on the workflow activities you have as this will not work if you have approvals or tasks being managed by that special workflow.

This workflow has multiple approvals and tasks, so it doesn't sound like that suggestion will work.

I just need to figure out a way to trigger this workflow (which runs against sc_request), whent the third variable/Order Guide Catalog Item is selected.

Brian Lancaster
Tera Sage

Sounds like you may need to have each of these items defined and then in a workflow use a script like this below to order the individual items.

 

var cart = new Cart(null, gs.getUserID()); //Create the cart as the current user

 var item = cart.addItem("sys_id of catalog item");

 cart.setVariable(item, 'var name', 'value');

 cart.setVariable(item, 'var name 2','other value');

 var rc = cart.placeOrder();

 

I am sorry, I do not understand how that solves my problem.  My issue isn't with selecting Catalog Items and adding them to the Cart.  Rather, it is in trgiggering the proper workflow based on which Catalog Item is selected in the Order Guide (specifically, when one of those workflows has to be based on sc_request instead of sc_req_item).