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 03:35 AM
Hello @Pallavi65 ,
you can try this code
var apps = current.variables.your_field_name.split(',');
for(var i=0; i<apps.length; i++){
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request = current.request;
gr.sys_id = current.sys_id;
gr.short_description = apps[i]; /
gr.insert();
}
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 04:23 AM
Hello Mohith,
It is good to see.
But only one thing not working. Can you help me to figure it out?
For the selected applications in the list collector field, there is an assignment group field present in the application and it has to populated in the Assignment group field of Catalog task. How can we do that as the Applications we are selecting is just a CI name (string field) on the Application table.
Regards,
Pallavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 04:29 AM - edited 08-31-2023 04:30 AM
@Pallavi65 in that case you have to do one more glide record to application table with the name and then get the assignment group
i am assuming that we need to query with sys_id of the application as it is list collector field which will give the sys_id of the referred record
var apps = current.variables.your_field_name.split(',');
for(var i=0; i<apps.length; i++){
var ci = new GlideRecord('cmdb_ci'); // replace your table name
ci.addQuery('sys_id',apps[i].toString()); // adjust your query accordingly
ci.query();
if(ci.next())
{
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request = current.request;
gr.sys_id = current.sys_id;
gr.short_description = apps[i];
gr,assignment_group= ci.suport_group // repalce your assigment group field name in application table
gr.insert();
}
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 04:47 AM
Hi Mohith,
It is creating only one task now.
My run script code: