- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 06:16 AM
Hi Every one,
Just want to know why I am getting result of this script like this. I am just trying to do this against problem table via background script. Kindly advise.
Script:
output:
*** Script: 0 52
*** Script: NaN 1
*** Script: NaN 28
*** Script: NaN 1
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 06:22 AM
Remove that '+' sign. That is trying to make a number of your 'number' field, while that's a string (PRB0012345). Since it's not a number, it sets NaN (Not a Number).
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 06:22 AM
Remove that '+' sign. That is trying to make a number of your 'number' field, while that's a string (PRB0012345). Since it's not a number, it sets NaN (Not a Number).
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 06:25 AM
var pr=new GlideAggregate('problem');
pr.addAggregate('COUNT');
pr.groupBy('parent.number');
pr.query();
while(pr.next())
{
gs.print(pr.getDisplayValue('parent.number')+" : "+pr.getAggregate('COUNT'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 06:27 AM
try this line
-> the + operator is unary plus operator in javascript
-> it is trying to convert the value to a number
-> if value is not a number then it's giving NaN or 0 (if value is empty or null)
gs.print(pr.getDisplayValue('parent.number') + " " + pr.getAggregate('COUNT'));
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