Loop thought list collector

Brian Lancaster
Tera Sage

I have a name change process where users select which application they use in a list collector where we have to manually update their username.   How can I loop thought the list collector so that I can create a separate task for each item selected in the list collector.

11 REPLIES 11

You might have to make sure that the 'myString' variable is a string object.   You can try this as your first line instead...



var myString = current.variable_pool.access_list.toString();


Here is the code I figured out.   This is looping through the list collector and comparing it to the table.   It then fires off notification if the one field in the list in null.


var array1 =[];


array1 = current.variables.listcollector.toString();


var array2 = [];


array2 = array1.split(',');


var Length = array2.length;


for (var i =0; i< Length; i++){


var app = GlideRecord("yourtable");


        app.addQuery('sys_id',array2[i]);


app.addQuery('field', 'true');


app.addNullQuery('field');


app.query();


if(app.next()) {


  gs.eventQueue('namechange', current, current.request.requested_for.email, app.field);


}


}


I know you posted this a long time ago, but it helped tremendously!   I'm trying to design a course through a workflow and splitting the users from the list collector worked perfectly!   Thank you!!!



  var array1 =[];


  array1 = current.variable_pool.homework_packet_users.toString();


  var array2 = [];


  array2 = array1.split(',');


  var Length = array2.length;


  for (var i =0; i< Length; i++){


            var tw = GlideRecord('u_training_workshop');


            tw.u_assignment = current.variable_pool.assignment_name;


            tw.u_due_date = current.variable_pool.assignment_due_date;


            tw.u_first_day_of_workshop = current.variable_pool.first_day;


            tw.u_service_center_reviewer = current.variable_pool.service_center_reviewer;


            tw.u_trainee = array2[i];


            tw.insert();


  }


I was not very good as javascript back then.   You do not need 2 arrays after seen some coding from a college you could probably change it to this which would be much more efficient and easier to read.



var users = current.variable_pool.homework_packet_user.toSting().split(',');


var Lenght = users.length;


for (var i=0; i< Length; i++){


            var tw = GlideRecord('u_training_workshop');


            tw.u_assignment = current.variable_pool.assignment_name;


            tw.u_due_date = current.variable_pool.assignment_due_date;


            tw.u_first_day_of_workshop = current.variable_pool.first_day;


            tw.u_service_center_reviewer = current.variable_pool.service_center_reviewer;


            tw.u_trainee = users[i];


            tw.insert();


}


mdsh
Giga Contributor

Hi John,



I created a similar business rule to create catalog tasks and assign to people selected in the list (I used Glide_list and added a field to the Catalog Task form itself). And it is creating as many tasks as the number of people selected. But it does not add the Assigned To value after the first iteration. So after the first task created, the rest 2 3 4 tasks are without Assigned_to field. I checked in gs.addInfoMessage() too, and it shows there. Can you help?



Here is my code for Before Update Business Rule:



(function executeRule(current, previous /*null when async*/) {


var abc = current.u_select_vertical_functional_managers.getDisplayValue(); // Variable name in my catalog task form ( a glide list)


gs.addInfoMessage(abc);


var xyz = abc.split(',');


for(var i=0; i<xyz.length;i++){


var gr = new GlideRecord('sc_task');


gr.initialize();


//gr.parent = current.sys_id;


gr.short_description="Complete Resource Estimation";


gr.request=current.request;


gr.request_item = current.request_item;


gr.parent = current.parent;


gr.assignment_group="Audio Visual Support Team";


gs.addInfoMessage(xyz[i]);   //showing all the values correctly


gr.assigned_to = xyz[i];


gr.insert();


}


})(current, previous);