- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2020 08:59 PM
Hi ,
I have a user 'A' which mapped 80 roles . Now need to create a new user 'B' and copy the same roles which has available in role 'A' ?
Steps
Export the user role to XML file .
2. Import the XML in user 'B'.
3. Getting the below error.
Please help to fix this issue.
Regards,
Sagaya.
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2020 09:25 PM
It's not straight forward for XML export/import.
you will have to run a script for this either one time schedule job or fix script
Sample below
createUserRoles();
function createUserRoles(){
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', 'userASysId');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('sys_user_has_role');
gr1.initialize();
gr1.user = 'userB SysId';
gr1.role = gr.role;
gr1.insert();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2020 09:23 PM
Hi Sagaya,
Sharing you the link of similar query which has two different solution, it might help you-
Warm Regards,
Shubham Bongulwar
Please mark helpful or correct if it helps!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2020 09:25 PM
It's not straight forward for XML export/import.
you will have to run a script for this either one time schedule job or fix script
Sample below
createUserRoles();
function createUserRoles(){
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', 'userASysId');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('sys_user_has_role');
gr1.initialize();
gr1.user = 'userB SysId';
gr1.role = gr.role;
gr1.insert();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader