Using list collector variables to create glide records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 09:43 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 10:59 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 11:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 11:13 AM
add logs and check if the value are present in scratchpad and variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 11:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 11:32 AM
use
gs.log(current.variables.variablename);