- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2016 03:53 AM
I did ask this yesterday but after going back and forth with some very helpful people I still haven't managed to get this working. Here's the scenario:
I have a cat item with the following variables:
bservice_name - string
bservice_bowners - list_collector (list of users)
Once submitted - the cat item is sent for approval, once approved, the workflow creates a new group using the bservice_name, this is the code:
var newgroup = new GlideRecord('sys_user_group');
newgroup.initialize();
newgroup.name = 'CA_BO_' + current.variables.bservice_name;
newgroup.insert();
workflow.scratchpad.GroupID = newgroup.getUniqueValue();
The new group is created without any issues and the sys_id of the new group is written to the scratchpad.
The next part is where I'm getting stuck, I need the users selected in the list collector (bservice_bowners) to be added to the new group.
The return from the list collector is stored as comma seperated sys_id's. I need to create a new record on the sys_user_grmember table for each of the users selected on the list collector.
The only way I believe I can do this is using an array.....but all the suggestions in the previous thread dont work. No record is created on the sys_user_grmember table.
Any help would be appreciated.
Many Thanks
Harry
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2016 08:24 AM
Here is your code
var users= current.variables.bservice_bowners.toString().split(',');
for(i=0; i<users.length; i++){
var gr= new GlideRecord('sys_user_grmember');
gr.initialize();
gr.group=workflow.scratchpad.GroupID;
gr.user=users[i];
gr.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2016 10:11 AM
Glad you got it working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2022 07:19 PM
Hey Abhinay Erra thanks a lot for this solution.
I had a similar problem and your comment helped me to solve it.
I alredy saved it in my presonal scripts library, thank you very much.