- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:33 AM
Hello experts ,
my requirement is
I want to create a report that A list of cost centers without having users.
Here cost center(cmn_cost_center) is different table and user(sys_user) is different table.
how to achieve this by using client script..?
Thanks in advance.
Best regards,
Raj
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:42 AM - edited 07-18-2023 06:45 AM
Hi there,
You won't be able to do it with client script, you'll need a server script of some sort (business rule, script include, etc.).
The below script will get you a list of cost centers that do not have any users:
var resultArr = [];
var costCenterGr = new GlideRecord('cmn_cost_center');
costCenterGr.query();
while (costCenterGr.next()) {
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery(gs.getMessage('cost_center={0}', costCenterGr.getUniqueValue()));
userGr.setLimit(1);
userGr.query()
if (!userGr.hasNext()) {
resultArr.push(costCenterGr.getUniqueValue());
}
}
gs.info(gs.getMessage('Cost centers with no users: {0}', resultArr.join()));
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:55 AM
Hi,
Seems there is a missing 'userGr.query();' line, before the 'if' statement. Otherwise the script seems to work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:56 AM
Yes, good catch -- I had edited my reply a couple minutes after I posted it to include that userGr.query() line.
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 08:02 AM
Hi Raj149,
chrisperry's report works for me, however in the Related List conditions, I didn't see "No" as a selection, but have "Less than 1".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 08:05 AM