TeHow to retrieve users from sys_user with the help of sysid of company and dept
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 05:42 AM
Hi All,
How to retrieve the list of users from sys_user table with the help of sys_id of dept and company. Lets suppose sys id of company is 123 and sys id of dept is 456. i want to retrieve all the users from sys_user table having company sysid as 123 and dept sys id as 456.
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 05:48 AM
Hi @Sachin G K1 ,
Write below code to retrieve the list of users from sys_user table
// Provide the sys_id of the company and department
var companyId = '<sys_id of the company>';
var departmentId = '<sys_id of the department>';
var userGR = new GlideRecord('sys_user');
// Add a company and department query conditions to the GlideRecord
userGR.addQuery('company', companyId);
userGR.addQuery('department', departmentId);
userGR.query();
while (userGR.next()) {
var userName = userGR.getValue('name');
var userEmail = userGR.getValue('email');
gs.info('User: ' + userName + ', Email: ' + userEmail);
}
Make sure to replace <sys_id of the company> and <sys_id of the department> with the actual sys_ids you want to use for filtering the users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 05:50 AM
Hi
PLease try the below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 06:00 AM - edited 05-25-2023 06:00 AM