ServiceNow GlideAggregate Count | Is it better than GlideRecord getRowCount()

https://youtube.com/live/pXjSXMS7Ajs

In this first (of hopefully many) live streams we take a look at ServiceNow GlideAggregate COUNT and why we might use it instead of GlideRecord getRowCount(). Many times we hear “dont use getRowCount, use GlideAggregate COUNT instead”! But why do people use one and not the other?

What are pros and cons…lets take a look

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideAggregateScopedAPI#r_ScopedGlideAggregateNext

https://developer.servicenow.com/blog.do?p=/post/glideaggregate/

    var inc = current.getUniqueValue(); //INC0009009
    var count = 0;

    /* GLIDE RECORD - GET ROW COUNT */
    var incTsk = new GlideRecord('incident_task');
    incTsk.addActiveQuery();
    incTsk.addQuery('incident', inc);
    incTsk.query();

    if (incTsk.hasNext()) {
        count = incTsk.getRowCount();

        gs.addErrorMessage("GlideRecord: Number of Open Incidents tasks = " + count);
    }

    /************************************/





    /* GLIDE RECORD - GET ROW COUNT */
    var agg = new GlideAggregate('incident_task');
    agg.addAggregate('COUNT');
    agg.addActiveQuery();
    agg.addQuery('incident', inc);
    //agg.groupBy('number');
    agg.query();

    if (agg.next()) {
        count = agg.getAggregate('COUNT');

        gs.info("GlideAggregate: Number of Open Incidents tasks = " + count);
    }
    /************************************/
Share

You may also like...