How to export a list of users with their group and roles in one click.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 10:33 AM
Hello All,
How to export a list of users with their roles na groups in one click?
Kind Regards
Arthur

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 10:36 AM
Type sys_user_has_role.list in the navigation filter. Once on that list, right-click on the header and export. You'll need to do the same for the sys_user_grmember table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:41 AM
Hi Arthur,
Well this can be done by the following configurations:
1. Create a UI Action with the following options
Name: Export User
Table: User (sys_user)
Order: 200
Form link: True
Show insert: False
Show update: True
Client True
Onclick exportUser();
Condition: gs.hasRole("admin")
Script:
function callExportCatalogItem() {
var url = new GlideURL('export_user.do');
url.addParam('sysparm_sys_id', gel("sys_uniqueValue").value);
var frame = top.gsft_main;
if (!frame){
frame = top;
}
frame.location = url.getURL();
}
2. Create a processor with the following options:
Name: ExportUser
Type: Script
Path: export_user
Script:
(function process(g_request, g_response, g_processor) {
var sysid = g_request.getParameter('sysparm_sys_id');
gs.log('** Exporting User ' + sysid);
//Name all the related lists
var exporter = new ExportWithRelatedLists('sys_user', sysid);
exporter.addRelatedList('sys_user_has_role', 'user');
exporter.addRelatedList('sys_user_grmember', 'user');
var RoleID = '';
var grpID = '';
var rol = new GlideRecord('sys_user_has_role');
rol.addQuery('user', sysid);
rol.query();
while(rol.next()){
RoleID = RoleID + ',' + rol.role.sys_id.toString();
}
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user', sysid);
grp.query();
while(grp.next()){
grpID = grpID + ',' + grp.group.sys_id.toString();
}
exporter.addQuerySet('role', 'sys_idIN' + RoleID);
exporter.addQuerySet('group', 'sys_idIN' + grpID);
exporter.exportRecords(g_response);
})(g_request, g_response, g_processor);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:43 AM
Hi ,
Small change in UI Action script.
function exportUser() {
var url = new GlideURL('export_user.do');
url.addParam('sysparm_sys_id', gel("sys_uniqueValue").value);
var frame = top.gsft_main;
if (!frame){
frame = top;
}
frame.location = url.getURL();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 12:25 PM
Thanks Dilip but this is not working. The file is empty.