- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 06:56 AM
I have created a custom action to run a script. But I am not sure how to access the variable set variables here.
Also I need to use this script in all the catalog items. So how can I do this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 07:08 AM
Hi @SHALIKAS ,
Interestingly there doesn't seem to be an OOTB way of accessing Variables from a Variable Set directly using the "Flow Designer support for Service Catalog".
Steps to do this for a MVS (for a Variable Set just use an object, not Array.object:
1. Create a custom Action:
Feed the custom action the RITM that you'll be using in the flow (I've been forced to feed it the RITM number/Sys ID, as for some reason unknown to me you can't feed the flow a single record, there is only multi record select).
2. Create a Script Step:
Set the input variable to the request item (number/sys ID). Now in the script you'll need to GlideRecord into the RITM process the data into an Objects Array. In the below case I have looped through a multi variable set and set the OUTPUT variable to the newly created object.Array.
(function execute(inputs, outputs) {
// ... code ...
var ritm = new GlideRecord('sc_req_item');
ritm.get(inputs.sc_req_item);
var objectArray = [];
var fullSet = ritm.variables.[YOUR VARIABLE SET NAME];
for ( var i = 0 ; i < fullSet.getRowCount() ; i++){
var item = {};
item.hostType = fullSet[i].[VARIABLE NAME 1];
item.hostName = fullSet[i].[VARIABLE NAME 2];
item.hostOperatingName = fullSet[i].[VARIABLE NAME 3];
item.networkZone = fullSet[i].[VARIABLE NAME 4];
item.dataCenter = fullSet[i].[VARIABLE NAME 5];
item.componentName = fullSet[i].[VARIABLE NAME 6];
item.applicationImplementationLanguage = fullSet[i].[VARIABLE NAME 7];
item.languageVersion = fullSet[i].[VARIABLE NAME 8];
item.applicationServer = fullSet[i].[VARIABLE NAME 9];
item.lifeCycleStage = fullSet[i].[VARIABLE NAME 10];
item.brand = fullSet[i].[VARIABLE NAME 11];
objectArray.push(item);
}
outputs.objectarray = objectArray;
})(inputs, outputs);
In the above case I've had to loop through depending on the row count, this is used in the case of a multi variable set (as the number of loops can vary from RITM to RITM).
Tip: Remember to set outputs.NAME and not outputs.LABEL (easy mistake to make).
3. Set the Script Steps Output Variables:
You'll now need to set the output variable of the Script Step to the same structure of the object.Array you've created. Currently Flow Designer supports String, Integer, Date/Time, Choice, True/False and Object as outputs in your object. See below for my setup.
4. Parsing your data back to your flow
For this step you'll need to create a new object.Array output variable and drop the script steps output variable to the subflow output variable value:
5. (Optional) Accessing data in Flow when multi variable set used.
In the case of pulling data from a multi variable set you'll have to create a forEach loop in your Flow and loop through the object.Array to access the data as you'll have a variable number of objects in that Array. In the Case of a Variable Set you can just use an object output and not an Array.object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 07:08 AM
Hi @SHALIKAS ,
Interestingly there doesn't seem to be an OOTB way of accessing Variables from a Variable Set directly using the "Flow Designer support for Service Catalog".
Steps to do this for a MVS (for a Variable Set just use an object, not Array.object:
1. Create a custom Action:
Feed the custom action the RITM that you'll be using in the flow (I've been forced to feed it the RITM number/Sys ID, as for some reason unknown to me you can't feed the flow a single record, there is only multi record select).
2. Create a Script Step:
Set the input variable to the request item (number/sys ID). Now in the script you'll need to GlideRecord into the RITM process the data into an Objects Array. In the below case I have looped through a multi variable set and set the OUTPUT variable to the newly created object.Array.
(function execute(inputs, outputs) {
// ... code ...
var ritm = new GlideRecord('sc_req_item');
ritm.get(inputs.sc_req_item);
var objectArray = [];
var fullSet = ritm.variables.[YOUR VARIABLE SET NAME];
for ( var i = 0 ; i < fullSet.getRowCount() ; i++){
var item = {};
item.hostType = fullSet[i].[VARIABLE NAME 1];
item.hostName = fullSet[i].[VARIABLE NAME 2];
item.hostOperatingName = fullSet[i].[VARIABLE NAME 3];
item.networkZone = fullSet[i].[VARIABLE NAME 4];
item.dataCenter = fullSet[i].[VARIABLE NAME 5];
item.componentName = fullSet[i].[VARIABLE NAME 6];
item.applicationImplementationLanguage = fullSet[i].[VARIABLE NAME 7];
item.languageVersion = fullSet[i].[VARIABLE NAME 8];
item.applicationServer = fullSet[i].[VARIABLE NAME 9];
item.lifeCycleStage = fullSet[i].[VARIABLE NAME 10];
item.brand = fullSet[i].[VARIABLE NAME 11];
objectArray.push(item);
}
outputs.objectarray = objectArray;
})(inputs, outputs);
In the above case I've had to loop through depending on the row count, this is used in the case of a multi variable set (as the number of loops can vary from RITM to RITM).
Tip: Remember to set outputs.NAME and not outputs.LABEL (easy mistake to make).
3. Set the Script Steps Output Variables:
You'll now need to set the output variable of the Script Step to the same structure of the object.Array you've created. Currently Flow Designer supports String, Integer, Date/Time, Choice, True/False and Object as outputs in your object. See below for my setup.
4. Parsing your data back to your flow
For this step you'll need to create a new object.Array output variable and drop the script steps output variable to the subflow output variable value:
5. (Optional) Accessing data in Flow when multi variable set used.
In the case of pulling data from a multi variable set you'll have to create a forEach loop in your Flow and loop through the object.Array to access the data as you'll have a variable number of objects in that Array. In the Case of a Variable Set you can just use an object output and not an Array.object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 03:38 AM
Hi @SHALIKAS ,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 04:19 AM
@SHALIKAS this is a very helpful post, it matches closely to what I am trying to achieve. Would you be able to elaborate a bit more on these steps copied below? If you don't mind, could you post screenshots of how you configure the Action Input and Output. Thank you ! 🙂
1. Create a custom Action:
Feed the custom action the RITM that you'll be using in the flow (I've been forced to feed it the RITM number/Sys ID, as for some reason unknown to me you can't feed the flow a single record, there is only multi record select).
2. Create a Script Step:
Set the input variable to the request item (number/sys ID).