
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2022 08:03 PM
Dear ServiceNow Experts,
I am trying to fulfill a request where a Catalog Item has a question/variable where if it is set to TRUE (checked), another 3 variables become visible and mandatory.
For example if in the form there is a question
Do you want to be happy? = TRUE
*Justificacition, Access Level, Who needs access. (these three variables become visible and mandatory).
There is another Catalog Item in the catalog that HAS the exact same questions (let's name it XYZ for this example), what I want is to automatically trigger that catalog item and create a new RITM with the values the user sets in Questions Justificacition, Access Level, Who needs access.
For that, I think I can pass the variables values via the workflow into a sub-workflow or parallel workflow activity.
I think we could just create a task with the variables values and assign it to the respective assignment group, or use an order guide. But for reporting and other matters they want a new RITM for that specific catalog item (XYZ).
I read I should set the on both main workflow and sub.
I did as follows:
MAIN WORKFLOW INPUTS
MAIN WORKFLOW SCRIPT
workflow.scratchpad.u_main_requested_for = current.variables.report_galleries_requested_by;
workflow.scratchpad.u_main_access_level = current.variables.acc_galry_accessto;
workflow.scratchpad.u_main_justification = current.variables.acc_galry_justification;
Parallel workflow activity configuration
THEN, Sub-flow preparation (inputs)
SUB-FLOW SCRIPT to get variables values
I CONFESS I TRIED ALL COMBINATIONS YOU SEE COMMENTED
// var reqFor = workflow.variables.u_requested_for;
// var AccLevel = workflow.variables.u_access_level;
// var just = workflow.variables.u_justification;
// var reqFor = workflow.inputs.u_sub_requested_for;
// var AccLevel = workflow.inputs.u_sub_access_level;
// var just = workflow.inputs.u_sub_justification;
var reqFor = workflow.variables.u_sub_requested_for;
var AccLevel = workflow.variables.u_sub_access_level;
var just = workflow.variables.u_sub_justification;
var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
var catItem = cart.addItem(gs.getProperty('catitem.reportaccessgalleires.id')); // Cat item sys_id is on a system property.
// Fill the variables
cart.setVariable('report_galleries_requested_by', 'reqFor');
cart.serVariable('access_level', 'AccLevel');
cart.setVariable('justification', 'just');
var rc = cart.placeOrder();
BOTH RITMs gets created, yet, the XYZ variables are empty, nothing passed through (or I can't figure out how to get the values).
I'm sure I am missing something or misplacing the code somewhere.
Thanks for your help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 10:20 PM
In my previous reply, the screenshot were not properly captured so I am adding an attachment:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2022 09:00 PM
HI
Refer to this thread :https://community.servicenow.com/community?id=community_question&sys_id=c36a0d78db7cab4467a72926ca96...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 10:08 PM
I could fulfill this by making little changes.
Important things to consider: the parent workflow does not requires inputs (as I set) if you are not returning values to it. So if you are passing the values to the sub-workflow ONLY, you just need to set the inputs in the sub-workflow.
In the Parent workflow, create a script activity to set the workflow scratchpad variables.
The actual script: here I am assigning values from variables to the scratchpad varible that I will use later to pass into the sub-workflow.
workflow.scratchpad.requested_for = current.variables.report_galleries_requested_by.getValue().toString();
workflow.scratchpad.access_level = current.variables.acc_galry_accessto;
workflow.scratchpad.justification = current.variables.acc_galry_justification;
workflow.scratchpad.environment = current.variables.report_galleries_environment;
workflow.scratchpad.user = current.variables.user.getValue().toString();
Now, drag and drop the sub-workflow into the editor.
Now assign the variables to the inputs (inputs you created for the sub-workflow will show up here:
So, for example, I created an input in the sub-workflow which label is "Justification" and column name is "u_justification".
In this step I am assigning the workflow.scratchpad.justification variable to that input as follows:
${workflow.scratchpad.justification}
You will assign each scratchpad variable to the corresponding input.
Finally, in the sub-workflow, you need to gather the values from the inputs, up until this point the inputs holds the values that comes from the parent workflow, now you have it available in the sub-workflow and you need to create a new script activity where you will get those values and use them
In my case, ended up as this:
var reqFor = workflow.inputs.u_requested_for;
var AccLevel = workflow.inputs.u_access_level;
var just = workflow.inputs.u_justification;
var environment = workflow.inputs.u_environment;
var accFor = workflow.inputs.u_user;
var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
var catItem = cart.addItem(gs.getProperty('catitem.reportaccessgalleires.id')); // Cat item sys_id is on a system property.
// Fill the variables
cart.setVariable(catItem,'report_galleries_requested_by', reqFor);
cart.setVariable(catItem,'report_galleries_environment', environment);
cart.setVariable(catItem,'justification', just);
cart.setVariable(catItem,'user', accFor);
// Set Access Level variable value based on parent workflow variables
if (workflow.inputs.u_access_level == "acc_galry_accessto_lev1") {
cart.setVariable(catItem,'access_level', 'level2');
} else if (workflow.inputs.u_access_level == "acc_galry_accessto_lev2") {
cart.setVariable(catItem,'access_level', 'level2');
} else if (workflow.inputs.u_access_level == "acc_galry_food_safety") {
cart.setVariable(catItem,'access_level', 'food_safety');
}
var rc = cart.placeOrder();
I hope this helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 10:20 PM