- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 01:32 PM
Hi, I am fairly new to servicenow so I apologize if my question is framed poorly. I have a service catalog item that uses a variable set to define a source/destination IP and port for a users firewall request. I am using a variable set so that we can have multiple groupings (rows) in the request. I am having this request trigger a workflow that will create an SCTask and populate it with the variable names/values from the variable set. I've poked around and can see how to populate the data when using variables but now when using variable sets.
Using run script workflow task how would I script it out to have it create and populate an SCtask with the proper information? Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 03:34 PM
Querying variable sets is not that straight forward. You will have to dot walk. The sample script I used and the outputs are included below and on the attachments. But here is a high level breakdown:
1) Query the RITM parent item with the varaible set
2) Ensure that you include the entire variable in a variable. It can be done in this format
variablename=gliderecordqueryobjectvariable.variables.variablesetname
in my script it would be rotmanSystems = ritmGR.variables.rotman_systems;
3) Get the row count so you know how many records to loop through
4) Loop through each row with getRow. You will be able to extract the column value as you loop through.
var rotmanSystems;
var itemID='fbec74bddb752c5043713423e2961973' //RITM SysID
//Query MRVS Object - Rotman Systems
var ritmGR = new GlideRecord('sc_req_item');
if(ritmGR.get(itemID)){
rotmanSystems = ritmGR.variables.rotman_systems;
}
//Row Counts for MVRS
var rotmanSystemsRowCount=rotmanSystems.getRowCount();//Total Rotman System Count (includes Salesforce)
//Iterate through the row records
for (var i=0;i<rotmanSystemsRowCount;i++){
var row=rotmanSystems.getRow(i);//Get Rotman System MVRS Row RECORD
var systemName=row.system_name.toString(); // Get value of system_name column
gs.print(systemName);
}
Please note the above example only shows how to query variable set values for each row. From what I understand querying is the roadblock you ran into.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 02:37 PM
Hi
Are you using the flow designer or workflow editor ? To my knowledge, the flow designer support for multi-row variable sets (MRVS) is rather poor at the moment. While I fully expect this will be improved in the future, may I suggest that you create your workflow in the workflow editor ?
You will be able to directly pull in the variables, including variable sets from your parent requested item onto the SC Tasks.
I'm assuming your goal is to have the variables show up on the tasks as well so there is no need to switch back and forth between RITM and SCTask. Let me know if I misunderstood.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 02:44 PM
I am using the workflow editor. Your assumption is correct we want the ops team using the SCtask to handle the request so all the information should be in there. Below is our current runscript for creating the sctask and populating it with variable data. This doesn't work for variable sets.
//Load the RITM record
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.request.sys_id);
gr.query();
while (gr.next()) {
// Get Owned Variables for Requested Item(RITM) and sort by Order
var ownvar = new GlideRecord('sc_item_option_mtom');
ownvar.addQuery('request_item.number', gr.number);
ownvar.addQuery('sc_item_option.value', '!=', '');
ownvar.orderBy('sc_item_option.order');
ownvar.query();
//Create a variable for ultimate goal of updating work notes on task
var items = "Summary of " + gr.number + ": " + gr.cat_item.getDisplayValue() + "\n\nPlease create the following firewall request.\n\n";
while (ownvar.next()) {
var field = ownvar.sc_item_option.item_option_new;
var fieldValue = ownvar.sc_item_option.item_option_new.name;
//Iterate through the inputs and add to items
items += field.getDisplayValue() + ":\n" + gr.variables[fieldValue].getDisplayValue().replaceAll(",", "\n") + "\n\n";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 03:34 PM
Querying variable sets is not that straight forward. You will have to dot walk. The sample script I used and the outputs are included below and on the attachments. But here is a high level breakdown:
1) Query the RITM parent item with the varaible set
2) Ensure that you include the entire variable in a variable. It can be done in this format
variablename=gliderecordqueryobjectvariable.variables.variablesetname
in my script it would be rotmanSystems = ritmGR.variables.rotman_systems;
3) Get the row count so you know how many records to loop through
4) Loop through each row with getRow. You will be able to extract the column value as you loop through.
var rotmanSystems;
var itemID='fbec74bddb752c5043713423e2961973' //RITM SysID
//Query MRVS Object - Rotman Systems
var ritmGR = new GlideRecord('sc_req_item');
if(ritmGR.get(itemID)){
rotmanSystems = ritmGR.variables.rotman_systems;
}
//Row Counts for MVRS
var rotmanSystemsRowCount=rotmanSystems.getRowCount();//Total Rotman System Count (includes Salesforce)
//Iterate through the row records
for (var i=0;i<rotmanSystemsRowCount;i++){
var row=rotmanSystems.getRow(i);//Get Rotman System MVRS Row RECORD
var systemName=row.system_name.toString(); // Get value of system_name column
gs.print(systemName);
}
Please note the above example only shows how to query variable set values for each row. From what I understand querying is the roadblock you ran into.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2021 04:04 PM