In my opinion some of the select scenarios would be:
- If it is known that the target table/record is always going to contain a small number of records
- A limit is set (for example using setLimit)
- If the GlideRecord is still used for other processing in addition to getRowCount
when to not use getRowCount()
see GlideRecord | ServiceNow Developers
The usual way (using GlideRecord.getRowCount()) can cause scalability issues, because it retrieves every record and then counts them
If there is a util for generic code, we could add a getCount function there and re-use it.
The snippet would look like
function getCount(sTable, sQuery) {
var nCount = 0,
gaRecord = new GlideAggregate(sTable);
if (sQuery || sQuery != '')
gaRecord.addQuery(sQuery);
gaRecord.addAggregate('COUNT')
gaRecord.query();
if (gaRecord.next())
{ nCount = gaRecord.getAggregate('COUNT'); }
return nCount;
}
Comments
Post a Comment