Create tasks based on number of inputs in list collector

Pallavi65
Tera Contributor

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:

Pallavi65_0-1693477489516.png

 

Pallavi65_1-1693477516845.png

 

 

 

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

19 REPLIES 19

@Pallavi65 can you post your latest script please?

THis is the latest script:

 

Pallavi65_0-1693491148725.png

 

Mohan raj
Mega Sage

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.

Harish Bainsla
Kilo Patron
Kilo Patron


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();

}

Ravindra H V
Tera Contributor

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.

 

RavindraHV_0-1739695959205.png

 

 

RavindraHV_1-1739695959207.png

 

Please mark it as helpful if you found this useful.