- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 02:30 PM
Hello all,
In the below script I am trying replace getRowCount.
Running on Before Insert Business rule. Can we replace gr.getRowCount() with if (gr.hasNext())?
Or can this be replaced with GlideAggreate as I am not sure how this getRecordClassName() function will work with GlideAggregate.
var curNum = current.number + '';
if(curNum) {
var recordClass = current.getRecordClassName();
var gr = new GlideRecord(recordClass);
gr.addQuery('number', curNum);
gr.query();
if(gr.getRowCount() > 0) {
var newNum = getNextObjNumberPadded();
current.number = newNum;
}
}
Thank you!
Regards,
Meenal
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 02:34 PM
You can replace with
if(gr.hasNext())
OR
if(gr.next())
Simple definition
hasNext() --> check whether any record found against the query
next() --> if record found then ready the record to perform an action
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 02:34 PM
You can replace with
if(gr.hasNext())
OR
if(gr.next())
Simple definition
hasNext() --> check whether any record found against the query
next() --> if record found then ready the record to perform an action
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 02:40 PM
use below code
var curNum = current.number + '';
if(curNum) {
var recordClass = current.getRecordClassName();
var gr = new GlideRecord(recordClass);
gr.addQuery('number', curNum);
gr.query();
if(gr.hasNext()) {
var newNum = getNextObjNumberPadded();
current.number = newNum;
}
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 02:44 PM
Regarding the GlideAggregate, you don't need that here as you are not concerned about the total count of records instead you just need to check whether or not the record returned against the applied query. So hasNext() is the best alternative in this scenario.
Muhammad