Before BR not executing , trying to get users count whose department is finance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 03:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 06:23 AM - edited 09-19-2024 06:27 AM
Hi @ravitejak
While Loop iterates over multiple records returned by a query, executing the block of code for each record until there are no more records to process
Use the below code
var users = new GlideRecord('sys_user');
users.addQuery('department.name', 'finance');
users.query();
var count = 0;
while (users.next())
{
count++;
}
gs.info(' User Count: ' + count);
Thanks
Eshwar
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 06:25 AM
The department field on the sys_user table is a reference, which means the value stored is a sys_id of the record you see on the Department table. In a GlideRecord you can either replace 'finance' in your script with the sys_id of the Finance record, or use
users.addQuery('department.name', 'Finance');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 06:43 AM
department is reference field and it will take sysID not the name. Try passing sysID you will get the count.
Exisiting:
users.addQuery('department','finance');
Change to
users.addQuery('department','sysID'); // get the 'Finance' sysID from cmn_department table