Create tasks based on number of inputs in list collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:26 AM
Hi everyone,
I have a list collector field on a catalog item.
User can be able to select n number of values into it.
So let's say for example, user has selected 3 inputs in the list collector field, so for Each input I am trying to create catalog task(one one task for one one input).
So, in the workflow I am using a Run script activity and getting all the inputs of the list collector field and storing in an array.
Below pics shows you the exact scenario:
So, can some one help me how to write script in for loop.
like:
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request = current.request;
gr.sys_id = current.sys_id;
now: the short description should be like this, (it should populate with first value of the array)
gr.short_description = ar[i]; //here 4Sight as in the above pic that is the first entry of the array.
gr.insert();
Like wise I want to create 3 catalog tasks (as the user selected 3 inputs in the list collector)
Please help me
Regards,
Pallavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:08 AM
@Pallavi65 can you post your latest script please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:12 AM
THis is the latest script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:37 AM
Hi @Pallavi65,
Try this below code, I hope this will helpful
var list = current.variables.u_application_name; //getting list variable
var arr = list.split(','); //converting list which comma delimited value to array
for (var i = 0; i < arr.length; i++) { //looping through array and creating task
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request = current.request;
gr.short_description = 'you requested application name is '+ar[i];
gr.insert();
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
Regards,
T Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:35 AM
for (var i = 0; i < selectedInputs.length; i++) {
var input = selectedInputs[i];
var catalogTask = new GlideRecord('sc_task');
catalogTask.initialize();
catalogTask.short_description = 'Catalog Task for ' + input;
catalogTask.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 12:53 AM
Hi ALL,
Instead of using a List Collector, you could try using an MRV (Multi-Row Variable) set. It will be easier to create multiple tasks based on location.
Please mark it as helpful if you found this useful.