Create the catalog task based on the check box selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 10:24 AM
Hello,
I have 20+ checkboxes on my catalog item. A separate catalog task should be created and assigned to the group for each selected checkbox.
Assignment Groups are different for each task.
Is there any other better solution apart from If activity for each checkbox as I have to add one if activity and catalog task activity for each checkbox which will have a total 20+ if and 20+ catalog task activities.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 10:27 AM
You can just configure 1 run script activity in your workflow to generate catalog task for different group based on checkbox selected.
You will have to add wait for condition in your workflow to wait for tasks to be closed as per your requirements.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 10:31 AM
Better & standard way would be to create a table (matrix kind of) that stores checkbox & corresponding group. This would be called in the Runscript activity of the workflow that creates tasks based on selection & group from value from table.
But this would require a table to be setup as base data & going forward with future releases ServiceNow has limit on no. of tables as well.
So, if this is one of case then you can configure your Run script activity of the workflow to take care of these 20 tasks rather than 20 different catalog tasks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 11:26 AM
As mentioned, you can create tasks dynamically via a Run Script activity. You would need to populate the different fields on the task form and insert a new record. You'd also need to set the parent of the tasks to be the RITM to keep the association and, finally, you would need to use a wait for condition to ensure that all tasks are closed before your workflow completes.
In your Run Script you can define a function to create the actual tasks and then iterate through your check boxes and call the function. Below is a quick example. You would need to pass a short description (string) and an assignment group (sys_id).
//You need to pass in the sys_id of the group you want to assign
//I also included the short descriptipn
createTask('This is a task', '8a4cb6d4c61122780043b1642efcd52b');
function createTask(short_description, assignment_group) {
var task = new GlideRecord('sc_task');
task.initialize();
task.short_description = short_description;
task.assignment_group = assignment_group;
//Associate the task to the RITM
task.parent = current.sys_id;
task.request_item = current.sys_id;
task.insert();
}
Then, before your end block, add a wait for condition:
var checkTasks = new GlideRecord('sc_task');
checkTasks.addQuery('request_item',current.sys_id);
checkTasks.addActiveQuery();
checkTasks.query();
if(checkTasks.next()){
answer = false;
}
else{
answer = true;
}
The above should be ok as a one-off solution, but if this is something you see that might be reused a lot, then I, too, would suggest using a table driven approach where everything could be reference fields.
If this was helpful or correct, please be kind and click appropriately!
Michael Jones - Proud member of the CloudPires Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 11:38 AM
Hi
My concrete answer to your question is: No.
Thinking about what you want to do with those Tasks (maybe wait until they are completed etc.) it will n ot turn out a a big benefit, to create the tasks by script. Afterwards, you need to check on the status of the single tasks as well.
So, maybe the benefit to only have one Run Script to create the task will be lost, when you want to wait on them and react accordingly.
So, my recommendation:
As long as the number of checkboxes is fixed, you can do as you proposed.
As soon as the number of checkboxes becomes variable, go ahead with the script option.
Let me know, if that answers your question and mark my answer as correct and helpful.
BR
Dirk