How to add bulk users in a particular assignment group in servicenow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 09:10 PM
Hi,
I have to add around 150 users in a particular assignment group with the help of import set in ServiceNow.
Please help me in how to do that with the help of import sets.
Thanks and regards,
Nikhil
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 05:36 AM
Ideally ServiceNow would include a CSV upload UI action on the sys_user_group.do page but it does not exists at this time.
For anyone that may come across this and is looking for a simple add hoc method, you can do this with a fix or background script. This example works in PDI and will add the 3 mentioned users to the built-in "LDAP Admins" group.
// Define the list of email addresses
var emailAddresses = [
'abraham.lincoln@example.com',
'abel.tuter@example.com',
'fred.luddy@example.com'
];
// Specify the group name or sys_id
var groupName = 'Your Group Name'; // Replace with your group name
var groupSysId = 'dc0db135c332010016194ffe5bba8f23'; // You can also use the group sys_id if you know it
// Find the group record
var group = new GlideRecord('sys_user_group');
var groupFound = false;
if (groupSysId) {
if (group.get(groupSysId)) {
groupFound = true;
} else {
gs.error('Group not found with sys_id: ' + groupSysId);
}
} else {
group.addQuery('name', groupName);
group.query();
if (group.next()) {
groupFound = true;
} else {
gs.error('Group not found: ' + groupName);
}
}
// Loop through the email addresses and add users to the group if the group is found
if (groupFound) {
emailAddresses.forEach(function(email) {
var user = new GlideRecord('sys_user');
user.addQuery('email', email);
user.query();
if (user.next()) {
var userInGroup = new GlideRecord('sys_user_grmember');
userInGroup.addQuery('user', user.sys_id);
userInGroup.addQuery('group', group.sys_id);
userInGroup.query();
if (!userInGroup.next()) {
var groupMember = new GlideRecord('sys_user_grmember');
groupMember.initialize();
groupMember.user = user.sys_id;
groupMember.group = group.sys_id;
groupMember.insert();
gs.info('Added user ' + user.user_name + ' (' + email + ') to group ' + group.name);
} else {
gs.info('User ' + user.user_name + ' (' + email + ') is already in group ' + group.name);
}
} else {
gs.error('User not found: ' + email);
}
});
gs.info('Script execution completed.');
} else {
gs.error('Group not found. Script execution aborted.');
}