Flow designer - custom actions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 11:04 PM
Hi Team ,
I would like to know how what script can be written in flow designer custom action to check if more than 2 check boxes variables are selected in the RITM .
I have got a sample code below that runs on client script but i need some adjustment in the code that i can use in custom action of flow designer so that depending upon the output i can continue the flow .
For example if two check boxes are selected i can assign a user to ABC team and if not i can assign user to XYZ team in the flow.
Sample code which requires adjustment :
function onChange(control, oldValue, newValue, isLoading) {
var mandatoryVars = ['option1', 'option2', 'option3', 'option4', 'option5'];
var requiredCount = 2;
var actualCount = 0;
for (var x = 0; x < mandatoryVars.length; x++) {
if (g_form.getValue(mandatoryVars[x]) == 'true') {
actualCount++;
}
}
if (actualCount>=requiredCount) {
return true;
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2024 12:56 PM
You need to create a Flow variable first. In the Flow designer, click the ellipsis icon on the top right and select 'Flow variables'
Then create a Flow variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2024 03:36 PM
Hi @Nadeem Basha ,
Hi @servicenow_devo ,
You can use the Get Catalog Variables action to get the variables and after that use the If and else flow logic based on your requirement.
Refer Below
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2024 03:44 PM
To adjust the given client script for use in a Flow Designer custom action in ServiceNow, you will have to rewrite it in a way that it can be executed in a server-side context rather than client-side. This means replacing g_form.getValue() which is used to get the value of fields on the client side, with a method that can retrieve the value of the variables associated with a Record Producer or a Catalog Item in the context of a Requested Item (RITM).
In the Flow Designer's custom action, you generally have access to the current record (in this case, the RITM record) via input variables that you define for your action. Assuming you are working with a Request Item (RITM) that contains these checkbox variables, your script would need to access these variables directly from the record.
Here is a sample script adapted for a Flow Designer Custom Action:
(function execute(inputs, outputs) {
// Define the variable names you are interested in
var mandatoryVars = ['option1', 'option2', 'option3', 'option4', 'option5'];
var requiredCount = 2;
var actualCount = 0;
// Loop through the variable names
mandatoryVars.forEach(function(variableName) {
// Access the variable from the RITM inputs
// Assuming `inputs` contains the RITM record and variables are directly accessible
// Note: The variables may be stored as 'true'/'false' strings or as boolean true/false
var value = inputs[variableName];
if (value === 'true' || value === true) { // Handle both string and boolean true
actualCount++;
}
});
// Determine the next step based on the count of selected checkboxes
if (actualCount >= requiredCount) {
// Assign to ABC team
outputs.assignTeam = 'ABC'; // Use `outputs` to pass data to the next step in the flow
} else {
// Assign to XYZ team
outputs.assignTeam = 'XYZ'; // Use `outputs` to pass data to the next step in the flow
}
})(inputs, outputs);
This script template assumes that:
- You have defined the input variables in your custom action to match the checkbox variables' names you're interested in.
- The inputs parameter represents the incoming data to your custom action, including these checkbox variables.
- The outputs parameter is used to pass data from your custom action to other elements in the flow, such as which team to assign the RITM to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2024 06:44 AM
Hi Klaus ,
Thank you for the response .
I have made few modifications in the script as per my requirement but the output value is coming as empty ,can you let me know what went wrong , i will paste the script below:
Also i would like to know how to pass the output value after calling the custom action in the flow?
(function execute(inputs, outputs) {
var mandatoryVars = ['Apple', 'Orange', 'Mango', 'Kiwi', 'Fig','];
var requiredCount = 2;
var actualCount = 0;
mandatoryVars.forEach(function(variableName) {
var value = inputs[variableName];
if (value === 'true' || value === true) { // Handle both string and boolean true
actualCount++;
}
});
if (actualCount >= requiredCount) {
outputs.result = 'true'; // Use `outputs` to pass data to the next step in the flow
} else {
outputs.result = 'false'; // Use `outputs` to pass data to the next step in the flow
}
})(inputs, outputs);
Thanks in advance