- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 05:21 AM
Hello Guys ?
I am working on a requirement, where I need to create a custom table in which we have a currency field.
It is some what like a auction amount kind where the new entry in the currency field should always be $25(minimum) more than the maximum value of that the current field in the table ?
so do we have any predefined method or I need to go with script ?
Thanks Guys....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 06:49 AM
Hi Naresh,
You can try below
var count = new GlideAggregate('yourTableName');
count.addAggregate('MAX', 'yourFieldName');
count.query();
if (count.next()) {
var max = count.getAggregate('MAX', 'yourFieldName');
gs.log("Maximum value for field yourFieldName is " + max);
}
http://wiki.servicenow.com/index.php?title=GlideAggregate#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 10:03 AM
Hi Sishir please comment on the following ....
1) did you check the code with highlighted in the image
though the value of "u_field_3" is defined as integer in the table, still do we need to typecast !
3)
the last two images is having only temp value changed to 50 look at the o/p.
Total values in the table = 12;
and values are following
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 10:17 AM
I can see in your table there is total 11 records.
when you run below code, how are you making sure that record will always get you the temp value as 50? The better way to use GlideAggregate to get the Max value of the field and then do the comparison (as sugegsted by Deepak).
var gr = new GlideRecord('u_table_1);
gr.query();
gr.next();
var temp = gr.u_field_3;
If field type is integer then i think type casting is not required, you can check and try.
in your 3rd screen shot you are using parseInt(gr.u_field_3) > temp, but variable temp is not an integer, you can change it to gr.u_field_r > parseInt(temp) and try.
It is always recommended to use getValue() instead of directly accessing the field value with gliderecord.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 11:38 AM
Hi Naresh,
may i know what exactly are you trying to accomplish here.
if i check the 4th line in your query , it will always return you minimum integer value .eg: if you have list of values stored in u_field_3 (10,20,30,50,60)
It will always give you 10. do you have any set of numbers that you need to compare with u_field_3 values.
var test='';
var abc= new GlideRecord('u_table_1');
abc.query();
while(abc.next())
{
test=abc.u_field_3;
if(test>50)
{
gs.print('it is a demo');
}
else
{
gs.print('help');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 11:38 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: GlideAggregate
Visit http://docs.servicenow.com for the latest product documentation