How can I pass variables into Subflows from CatalogItem

Felix20
Mega Guru

Hi everybody,

I have a special question, dont know if it works at all, but maybe somebody has a brilliant idea.

Problem:
I workflows, a core workflow and some subworkflows, maybe 2 or 3 layers.

Like that CatalogItem -> Core Workflow -> Subworkflow Layer 1 -> Subworkflow Layer 2

And I want to use activities in Subworkflow Layer 2, which do rest calls ect...
These activities need variables, which should be configurable in CatalogItem.
While ordering a catalogitem from shop, the configured input variables should be passed from catalogitem through core workflow through subworkflow layer 1 to subworkflow layer 2.

This is important, because the persons who will work on workflows are not the same who work on catalogitem (different teams) and the catalogitem guy may just choose an already existing workflow and just want to see, which variables he need to configure (set value of email body for example) without having a look in the script activities in worklfow directly.

That would definitely increase our productivity and reduce error massivly.

I just tried to define a input in subworkflow Layer 2 "MyInput" u_myinput and passed it while calling core workflow. But that u_myinput is not empty in subworkflow Layer 2 because i dont pass it from subworkflow Layer 1 and dont pass it from core workflow.

Does somebody have a brilliant idea how to pass inputs from catalogitem to lowest layer of subflows without passing it from each workflow to an other?

 

many regards

10 REPLIES 10

Luiz Lucena
Mega Sage

Found a way to achieve this.

For this task, I had to create an additional catalog item that did not need to appear on the Service Catalog portal.

From the master workflow, need to create a Run Script step that will call the other Requested Item.

This example, we have a New Hire form that will create the user and the additional task is to create the email account on the cloud.

find_real_file.png

The IF statement below is where we are going to pass the variables to the subflow.

The script is below:

var email = '689d8c86db836340d299dd0b5e9619de'; //sid for the email request
//create a new item in the request
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, email, 1); // 1 is the qty 
reqHelper.rebalanceRequest(current.request);

//find the item and update itsvariables


var grReqItem = new GlideRecord('sc_req_item'); 
grReqItem.addQuery('request', current.request);   
grReqItem.addQuery('cat_item',email);   
grReqItem.addQuery('parent','');
grReqItem.query();   


if(grReqItem.next()) {
	grReqItem.variables.requested_for = current.variables.requested_for;
	grReqItem.variables.u_requested_by = workflow.scratchpad.affected_user;
	if (current.variables.nh_need_email == 'yes'){
	grReqItem.variables.contractor_flag = 'Y';
} else {
	grReqItem.variables.contractor_flag = 'N';
}
	//grReqItem.variables.mp_shipping_address = current.variables.nh_shipping_address;
	grReqItem.parent = current.sys_id;
	grReqItem.location = current.variables.nh_office;
	grReqItem.update();
}

 

On the subflow, you will need another Run Script to pass to the scratchpad the variables you are going to need on the subflow:

find_real_file.png

Script is here:

var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.u_requested_by;
req.update();

workflow.scratchpad.midserver = gs.getProperty('atc.orchestration.mid.server');
workflow.scratchpad.user = current.variables.u_requested_by.source;
workflow.scratchpad.contractor_flag = current.variables.contractor_flag;