- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2016 08:53 PM
Hi,
I have two grps one newly created as permission type grp(X) and another existing support type grp (Y).
The support type grp(Y) has 900 + users. I need all the members of Y grp to be copied to X grp through background script.
Can any one help us with the background script for this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2016 09:03 PM
var groupXid = 'sys_id_of_group_X';
var groupYid = 'sys_id_of_group_Y';
var newGr;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupYid);
gr.query();
while (gr.next()) {
newGr = new GlideRecord('sys_user_grmember');
newGr.initialize();
newGr.group = groupXid;
newGr.user = gr.user;
newGr.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2016 09:03 PM
var groupXid = 'sys_id_of_group_X';
var groupYid = 'sys_id_of_group_Y';
var newGr;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupYid);
gr.query();
while (gr.next()) {
newGr = new GlideRecord('sys_user_grmember');
newGr.initialize();
newGr.group = groupXid;
newGr.user = gr.user;
newGr.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2016 09:19 PM
Great minds code alike
https://youtube.com/watch?v=zYi8KhP9SUk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 09:04 AM
Hello,
I've used this code and what it did for me was it duplicated the users from the source group.
I made minor modifications to be easier to for me to read.
var copy_to = 'sys_id of target group';
var copy_from = 'sys_id of source group';
var newGr;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', copy_from);
gr.query();
while (gr.next()) {
newGr = new GlideRecord('sys_user_grmember');
newGr.initialize();
newGr.group = copy_to;
newGr.user = gr.user;
newGr.insert();
}
Are you able to help me check where failed?
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2016 09:16 PM
Here ya go. Hope it helps,
//sys_id of the group you are copying from
var copy_from = '09851ff3c3123100918bb4ad81d3aea7';
//sys_id of the group you are copying to
var copy_to = '419d4913db0622009b4470adbf9619a2';
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", copy_from);
gr.query();
while (gr.next()) {
gs.log(gr.user);
var rec = new GlideRecord('sys_user_grmember');
rec.initialize();
rec.group = copy_to;
rec.user = gr.user.sys_id;
rec.insert();
}
https://youtube.com/watch?v=zYi8KhP9SUk