Automation to sync user, group and role from Production to Lower Instances
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 06:13 PM
Hi i have a requirement to automate user, group and roles from production to lower instance so that the syncing will be done automatically rather than export and import or manually adding the roles, Any ideas on how to achieve this through automation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 07:29 PM
Hi @Cent?,
An idea is create an schedule job, define an date, and collect all information in csv archive
Here a code example
var gr = new GlideRecord('sys_user');
gr.addQuery('active', true);
gr.query();
// CSV Header
var csv = 'user_name,email,full_name,groups,roles\n';
while (gr.next()) {
var userSysId = gr.sys_id.toString();
var userName = gr.user_name.toString();
var email = gr.email.toString();
var fullName = gr.name.toString();
// Search user groups
var groups = [];
var grGroups = new GlideRecord('sys_user_grmember');
grGroups.addQuery('user', userSysId);
grGroups.query();
while (grGroups.next()) {
var group = grGroups.group.name.toString();
if (group) groups.push(group);
}
// Search user Role
var roles = [];
var grRoles = new GlideRecord('sys_user_has_role');
grRoles.addQuery('user', userSysId);
grRoles.query();
while (grRoles.next()) {
var role = grRoles.role.name.toString();
if (role) roles.push(role);
}
// Add to csv separately by coma
csv += [
userName,
email,
fullName,
'"' + groups.join(';') + '"',
'"' + roles.join(';') + '"'
].join(',') + '\n';
}
// Create the CSV
var exportName = 'user_export_with_groups_roles_' + new GlideDateTime().getValue() + '.csv';
var attachment = new GlideSysAttachment();
attachment.write('sys_user', '-1', exportName, 'text/csv', csv);
Once do you have this archive with all information that you need
You may create a transform map, in dev, to import those information
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 07:42 PM
Hi @Rafael,
Thanks for the reply will try it out and update, this scheduled job will be configured in dev and automatically it will gather the newly created or updated user/group/role information from prod to dev instance?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 07:48 PM
This scheduled job will be configured in prod and automatically it will gather the newly created or updated user/group/role information from prod to dev instance
The idea is keep all the prod information as same as dev or lowers instances.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 08:29 PM
@Rafael,
I tried it first for non prod instance and click execute now, where can i find the created csv file of the scheduled job?