Split a List Collector Variable to an array

Dan R
Kilo Expert

Good Afternoon SNC,

 

I have a form on the Service Portal that allows end users to request 1 or more users be added to a resolver group. They do this by selecting users from a list collector (variable name: members) and moving them from the left-side of the list collector to the right-side. The list collector references the sys_user table.

 

In order for me to fulfill this request, I have to go 1-by-1 through each of the users on the list collector, take their user_name and add it to a group in Active Directory. 

My issue here is, when this list of users to add is VERY long, it becomes extremely tedious to go 1-by-1 to get the user_name of each employee.

 

My thought here was that I could have a script run in the "advanced script" section of the Catalog Task in the Workflow, and have script:

1- take the 'members' list collector and create an array of values

2- take array of values and run a GlideRecord on the sys_user table to find the associated user_name for each employee

3- take the user_name of each employee and put it into a new array

4- display new array of user_name's in a multi-line text variable I named: admin_only

 

I tried giving this a stab but for some reason I feel like I'm getting stuck very early on in the array-creation process. Does anyone have insight into how I can best accomplish what I'm trying to do here?

 

Thanks in advance,

 

Dan R

1 ACCEPTED SOLUTION

Prateek kumar
Mega Sage

try

var list = current.list_collector_variable.toString();
var listSplit = list.split(',');

for(var i=0; i<listSplit; i++){
//Do something here
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

6 REPLIES 6

I stumbled upon your thread trying to get something similar to work for a requirement on one of my Catalog Items.

I have a list collector to select the list of users in the on the Portal.

The users (display value) is presented as a Variable on the generated RITM and SCTASK

I'd like to have a separate variable that shows the user_id and another showing the email address of the selected users.

I tested your script in a Catalog client script, and also as a BR but neither option would produce any results for me.

Should your code here work in a BR? Should it work in Portal? Do you have any tips or advice on how to get that working?

 

Thanks!

 

Thanks!

fyi you left the .length off from the listSplit within the for loop. My code has it corrected.