- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 11:57 PM
Hi guys
I have a requirement where once the catalog item is submitted a catalog task should be created for each variable which are marked true(these are checkboxes)
The short description also should be variable label name
Since there are about 10 checkboxes,any idea how to do this by looping?
thanks
bimsari
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:26 AM
Hello @Community Alums ,
You can achieve this requirement by using Flow Designer with a combination of actions and loops. Here's a step-by-step guide:
Create the Flow:
- Go to Flow Designer and create a new Flow.
- Set the trigger to "Catalog Item Requested."
Add Actions to the Flow:
- Add a "Create Task" action.
- Use the Script step to loop through the variables and create tasks for those that are marked true.
Loop Through Variables:
- You can use a Script step to loop through the variables.
Here is an example script that you can use in the Flow Designer:
- You can use a Script step to loop through the variables.
(function execute(inputs, outputs) {
// Get the current request item (RITM)
var gr = new GlideRecord('sc_req_item');
gr.get(inputs.request_item_id);
// Get the variables from the RITM
var variables = gr.variables;
// Loop through each variable
for (var v in variables) {
var variable = variables[v];
// Check if the variable is a checkbox and is true
if (variable.getType() === 'boolean' && variable.getValue() === 'true') {
// Create a new catalog task
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = inputs.request_item_id;
task.short_description = variable.getQuestion().getLabel();
task.insert();
}
}
})(inputs, outputs);
Define Inputs and Outputs:
- Ensure you define the necessary inputs for the script action. For example, inputs.request_item_id should be the RITM ID that you can get from the trigger or a previous action.
Add Conditions (Optional):
- If you want to add any additional conditions or actions based on the catalog item or other variables, you can do so before or after the loop.
Test the Flow:
- Test the flow by submitting a catalog item with the checkboxes and verify that tasks are created correctly.
- Test the flow by submitting a catalog item with the checkboxes and verify that tasks are created correctly.
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:26 AM
Hello @Community Alums ,
You can achieve this requirement by using Flow Designer with a combination of actions and loops. Here's a step-by-step guide:
Create the Flow:
- Go to Flow Designer and create a new Flow.
- Set the trigger to "Catalog Item Requested."
Add Actions to the Flow:
- Add a "Create Task" action.
- Use the Script step to loop through the variables and create tasks for those that are marked true.
Loop Through Variables:
- You can use a Script step to loop through the variables.
Here is an example script that you can use in the Flow Designer:
- You can use a Script step to loop through the variables.
(function execute(inputs, outputs) {
// Get the current request item (RITM)
var gr = new GlideRecord('sc_req_item');
gr.get(inputs.request_item_id);
// Get the variables from the RITM
var variables = gr.variables;
// Loop through each variable
for (var v in variables) {
var variable = variables[v];
// Check if the variable is a checkbox and is true
if (variable.getType() === 'boolean' && variable.getValue() === 'true') {
// Create a new catalog task
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = inputs.request_item_id;
task.short_description = variable.getQuestion().getLabel();
task.insert();
}
}
})(inputs, outputs);
Define Inputs and Outputs:
- Ensure you define the necessary inputs for the script action. For example, inputs.request_item_id should be the RITM ID that you can get from the trigger or a previous action.
Add Conditions (Optional):
- If you want to add any additional conditions or actions based on the catalog item or other variables, you can do so before or after the loop.
Test the Flow:
- Test the flow by submitting a catalog item with the checkboxes and verify that tasks are created correctly.
- Test the flow by submitting a catalog item with the checkboxes and verify that tasks are created correctly.
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 06:41 PM
Thank you so much for your reply. This code worked!!! , I had to change