- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 09:25 AM
i have a requirement to update the existing groups and group members, and roles by using the transform map and data source..
all this information was stores in a Excel, i have to upload that file using data source and update the existing data.
Do i need to create data source and transform maps for different tables like one for Group table, and another for group members table, and another for Roles table.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 10:45 AM - edited 05-12-2025 10:48 PM
Hello @VSN ,
You can do this using a single Data Source with two Transform Maps.
The 1st Transform Map would target the Group [sys_user_group] table, and would have field maps for the Name (coalesce enabled) and Manager columns.
To add the roles to the groups you need an "onAfter" Transform Script on the first Transform Map:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var roleNames = source.getValue('u_roles').split(',');
var groupId = target.getUniqueValue();
roleNames.forEach(roleName => {
var gr = new GlideRecord('sys_group_has_role');
gr.addQuery('group', groupId);
gr.addQuery('role.name', roleName);
gr.query();
if (gr.hasNext()) return;
gr.initialize();
gr.setValue('group', groupId);
gr.setDisplayValue('role', roleName);
gr.insert();
});
})(source, map, log, target);
The 2nd Transform Map would target the Group Member [sys_user_grmember] table, and would map the Name and User ID columns (both with coalesce enabled).
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 01:01 PM
That solution not working and we are not creating new role, we are just adding the existing role to group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 10:26 PM
Hello @VSN ,
The script is not creating new roles, it adds the roles mentioned in the Roles column of the Excel sheet to the Group.
The solution definitely works, as I have tested it using an Excel sheet that looks exactly like yours before posting it.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 02:11 AM
it was ignoring the values, not inserting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 10:36 PM
approach is already shared by @Robert H . Please start from your side as it will be learning for you as well
you should get details from docs, youtube videos
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 01:04 PM
Script is not working.because we are adding the existing record of group. Not creating the new roles.