- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:15 AM
Scenario: I have retrieved some numbers by gliderecord and stored in a variable, now i have to find the smallest and largest number from that list by using below code but it is not working.
var x = 1,2,3,4,5,6 //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = [x];
var min = Math.min.apply(Math,array);
gs.info(min);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:38 AM
If you have stored those values as string then you can use below script :
var x= "1,22,8,3,4,5,6"; //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = x.split(",");
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);
If you have stored those values as array of numbers then you can use below script :
var array = [1,22,8,3,4,5,6]; //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:26 AM
Hi
please use
var arrNumbers = [1,22,8,3,4,5,6];
gs.info(Math.max.apply(null, arrNumbers));
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:28 AM
Hi,
Please refer
How to get the MIN, MAX, AVG and SUM values from a table using the GlideAggregate function
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 05:38 AM
If you have stored those values as string then you can use below script :
var x= "1,22,8,3,4,5,6"; //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = x.split(",");
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);
If you have stored those values as array of numbers then you can use below script :
var array = [1,22,8,3,4,5,6]; //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP