When getRowCount() usage is permissable

 In my opinion some of the select scenarios would be:
  1. If it is known that the target table/record is always going to contain a small number of records
  2. A limit is set (for example using setLimit)
  3. 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

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage

variable advanced reference qualifier example