Adding users in the group with Transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 04:49 AM - edited 10-07-2024 04:50 AM
Hello,
I am trying to add users in the group with XL sheet using with Transform map. And I am using below code please correct me.
** OnBefore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 05:13 AM
Please try once bellow updated script:
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
// Get the user by username
var usr = new GlideRecord('sys_user');
if (usr.get('user_name', source.user_name.toString())) {
// Get the group by name
var grp = new GlideRecord('sys_user_group');
if (grp.get('name', source.Group.toString())) {
// Check if the membership already exists to avoid duplicates
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('user', usr.sys_id);
grMember.addQuery('group', grp.sys_id);
grMember.query();
if (!grMember.hasNext()) {
// Insert group membership
grMember.initialize();
grMember.user = usr.sys_id;
grMember.group = grp.sys_id;
grMember.insert();
log.info('Added user ' + usr.user_name + ' to group ' + grp.name);
} else {
log.warn('User ' + usr.user_name + ' is already a member of group ' + grp.name);
}
} else {
log.error('Group not found for name: ' + source.Group);
}
} else {
log.error('User not found for username: ' + source.user_name);
}
})(source, map, log, target);
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 05:18 AM
Hi,
Let me know the challenge you are facing.
Is the User and Group already present in the system? If not, then you may need to create.
What is the target table of the Transform map?
There is a chance that blank records created in import set if no other operation is done.
If you are not doing any other operation with the transform map, then add this line in the above transform map script
ignore = true;
Palani