How to access table used in List collector Variable ?

vignathareddy
Kilo Contributor

I am developing a Request Form using Service Catalog. This Request form has a List Collector tab, hence accepts multiples values populated @in List table.

Please help me out to understand how to access the data in Workflow (using Activities) for the values selected in List Collector in the Request form   ?

2.PNG

Above is my Request Form , where "Please Select Group name" is a List Collector which takes values from already created table : mpa_group with two columns : group_id and group_name.

If above three values are selected by user, I got the values displayed in Workflow using statement : current.variables.u_groupid.getDisplayValue().

And this variable shows all three values, but how can I work on each value separately and get the group_id assosciated with this group_name from table ?

4 REPLIES 4

JJ1
Kilo Guru

You can split the sys_id of selected groups in list collector to an array and loop through it and get the desiered value from the table



var grps = current.variables.u_groupid.toString();


var arry = grps.split(',');


For (i = 0; i<arry.length ; i++)


{


gs.info(arry[i]); //this will the groups sys_id


}


Thanks.


prasad48
Tera Guru

Write some thing like below



var getrecord= new GlideRecord("tablename");


getrecord.addQuery("sys_id","IN", current.variables.u_groupid);


getrecord.query();


while(getrecord.next())


{


//write your logic


}



OR



Information saves by separating by comma so you can split by comma and loop it to get separately


sachin_namjoshi
Kilo Patron
Kilo Patron

List collector variables values are stored in array.


You need to glide array to iterate for each record and then use them in your workflow script.



Please check below sample script for iterating via list collector values.



UpdatePersonalReports();




function UpdatePersonalReports(){



var rpt;


var rpt1;


var rpt_sysid;


var report_list = current.variable_pool.report_names.toString();// this is list collector vairable


//gs.log("Selected reports are" + 'report_list');


var arr = report_list.split(",");


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


rpt = new GlideRecord('sys_report_users_groups');


rpt.initialize();


rpt.report_id = arr[i].toString();


rpt.group_id = current.variable_pool.select_group.toString();


//rpt.report_id.user = "group";


rpt.insert();


rpt1 = new GlideRecord('sys_report');


//rpt_sysid = rpt1.sys_id.toString();


rpt1.addQuery('sys_id',arr[i].toString());


rpt1.query();


//gs.log("Report Name from sys_report " + rpt1.rpt_sysid);


//gs.log("Report Name for group " + rpt.report_id);


while(rpt1.next()){



gs.log("Report Name from sys_report " + rpt1.sysid);


      gs.log("Report Name for group " + rpt.report_id);


rpt1.user = "group";


rpt1.update();


}



}


}



Regards,


Sachin