- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 08:23 AM
Hi all,
I'm trying to count distinct users based on the payload field in the sys_audit_delete table.
I want to count each user (based on the display_value attribute in the tag) only once, even if they appear in multiple records. For example, if "Alex Walker" appears in 3 records and "Alex Brown" in 2, the total count should be 2.
I’m using the following script in a Performance Analytics indicator, but it always returns 1, even when I know there are multiple users:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 09:19 AM - edited ‎06-27-2025 09:54 AM
@Ankur Bawiskar, thanks for your reply but i figured out that i am using count distinct script so returning length won't get the result
so i have used script like this and it is working
(function() {
var payload = current.payload;
var match = payload.match(/<user[^>]*display_value="([^"]+)"/i);
if (match) {
gs.info('PA Test 2: ' + match[1].trim());
return match[1].trim();
}
return '';
})();
Returning name from payload
count distinct automatically identifes unique
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 08:35 AM - edited ‎06-27-2025 08:51 AM
@Ankur Bawiskar , can you please look into this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 09:10 AM
try this
(function() {
var grAudit = new GlideRecord('sys_audit_delete');
grAudit.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^tablename=sys_user_grmember^ORtablename=sys_user_has_role');
grAudit.query();
var userSet = {};
while (grAudit.next()) {
var payload = grAudit.getValue('payload');
var match = payload && payload.match(/<user[^>]*display_value="([^"]+)"/i);
if (match) {
var displayName = match[1].trim().toLowerCase();
userSet[displayName] = true;
}
}
return Object.keys(userSet).length;
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 09:19 AM - edited ‎06-27-2025 09:54 AM
@Ankur Bawiskar, thanks for your reply but i figured out that i am using count distinct script so returning length won't get the result
so i have used script like this and it is working
(function() {
var payload = current.payload;
var match = payload.match(/<user[^>]*display_value="([^"]+)"/i);
if (match) {
gs.info('PA Test 2: ' + match[1].trim());
return match[1].trim();
}
return '';
})();
Returning name from payload
count distinct automatically identifes unique