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 05:02 AM
@Pallavi65 Do one thing do not store the apps in applications variable remove that and directly split it like below
var apps = current.variables.your_field_name.getDisplayValue().split(',');
for(var i=0; i<apps.length; i++){
var ci = new GlideRecord('cmdb_ci'); // replace your table name
ci.addQuery('name',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 05:09 AM - edited 08-31-2023 05:13 AM
Hi Mohith,
No luck.
Still it is creating only one task when I selected 3 apps.
I have kept gs.log message inside for loop and it is coming 3 times as expected, but why it is creating only one task?
Regards,
Pallavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:13 AM
try replacing it like below
var apps = current.variables.your_field_name.getDisplayValue().toString().split(',');
Also can you try putting some logs inside for loop and then also inside if statement so that we can see how many times the loop is running
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:22 AM
Hi Mohith,
I selected 3 applications.
Inside for loop log message is coming 3 times but inside if loop only once.
Regards,
Pallavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:30 AM
@Pallavi65 check if you have all the three records in your table with exact names with out any spaces?