what is the signance of set limit function

Kishore Babu S
Tera Contributor

what is the signance of set limit function

5 REPLIES 5

Shishir Srivast
Mega Sage

limit [setLimit()] function helps to get how many records you want to retrieve in the GlideRecord(). http://wiki.servicenow.com/index.php?title=GlideRecord#setLimit


if you want to get the top 10 latest created record from a table then you can give setLimit(10) in the GlideRecord().



Let us know if you are looking anything specific.


Harsh Vardhan
Giga Patron

after execution of query . you can limit the number of records that your query will return.


eg:


if you will query of incident table to check how many active incident is available then you can simply write glide record then it will return you list of incidents number now you only want to 10 records rather than all incidents then in such scenario you will use setLimit();



var abc= new GlideRecord('incident');


abc.addActiveQuery();


abc.query();


while(abc.next())


{


gs.print(abc.number);


}



with out setLimit.png




var abc= new GlideRecord('incident');


abc.addActiveQuery();


abc.setLimit(10);


abc.query();


while(abc.next())


{


gs.print(abc.number);


}



with setLimit.png



hope it will help you


That was very clear and although I didn't ask this I have been looking around for such an example fo this question. Thank You!

glad it helped you