Using list collector variables to create glide records

Harry Campbell2
Mega Guru

Hello Everyone.

I have request with a list collector where a user selects users to be added to a group.

What is the best way to take the selected users from the list collector and add them to the selected group?

I'm guessing the best way to do this in a workflow would be to create a new glide record on the sys_user_grmember table   but I cant figure out how to pass all the sys_id's of the selected users into the script that creates the new record.

Hope that makes sense.

Thanks

Harry

29 REPLIES 29

So can you try changing the variable name in the code provided above? That should work now!!


Sorry, the spelling mistake was just on the gs.log line.



So the scratchpad shows the sys_id of the group:



{"GroupID":"f18c8db60f692a002e511efae1050e0a"}



And the script log shows 2 sys ID's of the users I selected in the list collector:



0f6818f144112c404eebd0bd54531376,053f0fd543d850004eeb673ba24afcaf



but still no luck.




Kalaiarasan Pus
Giga Sage

This is what we had done in past. This also check if the user is already a member of the group.



var userID=current.variables.requested_user; //replace variablename


var checkGroups = current.variables.group_list.split(','); //replace the list collector name


  for(var numberOfGroups=0;numberOfGroups<checkGroups.length;numberOfGroups++)


  {


  var checkMembership = new GlideRecord('sys_user_grmember');


  checkMembership.addQuery('user',userID);


  checkMembership.addQuery('group',checkGroups[numberOfGroups]); // Store users group sys_id


  checkMembership.query();


  if(!checkMembership.next())


  {


  checkMembership.initialize();


  checkMembership.user = userID;


  checkMembership.group = checkGroups[numberOfGroups];


  checkMembership.insert();


  }


  }


This looks like the groups are in the list collector but it is the users that need to be passed.



The group is also created by the workflow and is saved to the scratchpad using workflow.scratchpad.GroupID


Let me see if I have your design correct:


1. You have a list collector that collects a list of users and stores that in a variable called bservice_bowners


2. You have another string variable that is used to define the group to create.


3. Within your workflow, you create the group and store the sys_id of that created group in a workflow scratchpad variable called GroupID


4. You want to add the list of users that are stored in the variable to the group created in step 3.



Please confirm that this is your design so we can formulate our solutions accordingly.