Any Predefined Method to find a maximum value of a field ?

naresh1019
Mega Expert

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....

1 ACCEPTED SOLUTION

Deepak Ingale1
Mega Sage

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


View solution in original post

8 REPLIES 8

Deepak Ingale1
Mega Sage

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


Hi Deepak ,



yup will implement on Monday and will come back to you, if any issues. Thanks for the response. By the what is the best resource to master Scripting (Client Side and Server Side )


one more thing, i am unable to understand the o/p of this small if condition code ! can you help me out .....



find_real_file.png



for the above code, the o/p


find_real_file.png



find_real_file.png


After changing the value to 50 which is the actual value of temp the following is the o/p


find_real_file.png


information: u_field_3 is of type integer in the table


can you comment on this .


for your understanding, It should be like.



var gr = new GlideRecord('u_table_1);


gr.query();


while(gr.next())


{


if(parseInt(gr.getValue('u_field_3')) > 50)


gs.print('Hello');


else


gd.print('Boxer');


}