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

var usersList=current.variables.bservice_bowners.split(',');


var groupID = workflow.scratchpad.GroupID;


  for(var numberOfUsers=0;numberOfUsers<usersList.length;numberOfUsers++)


  {


  var checkMembership = new GlideRecord('sys_user_grmember');


  checkMembership.addQuery('user',usersList[numberOfUsers]);


  checkMembership.addQuery('group',groupID); // Store users group sys_id


  checkMembership.query();


  if(!checkMembership.next())


  {


  checkMembership.initialize();


  checkMembership.user = usersList[numberOfUsers];


  checkMembership.group = groupID;


  checkMembership.insert();


  }


  }


I'm afraid this isn't working either. There is no fault description or error, the eorkflow just moves onto the next activity as normal. But nobody gets added to the new group.


add logs and check if the value are present in scratchpad and variable.


I can see the Group ID on the scratchpad:



{"GroupID":"f18c8db60f692a002e511efae1050e0a"}



This error appears multiple times in the workflow log:



Stage not found in future. ID:14cc45f60f692a002e511efae1050ee5 future: [10cc45f60f692a002e511efae1050ee5, 90cc45f60f692a002e511efae1050ee5, 54cc45f60f692a002e511efae1050ee5]



I cannot see the variables on the workflow context.


use



gs.log(current.variables.variablename);