ServiceNow pass a GlideRecord query to a GlideAggregate

 var grInc=new GlideRecord('incident');
grInc.addQuery('state','1');
grInc.addEncodedQuery('sys_created_onONThis year@javascript:gs.beginningOfThisYear()@javascript:gs.endOfThisYear()');
grInc.query();

var sQuery=grInc.getEncodedQuery();
gs.print(sQuery);

var iCount=_countRecords('incident', sQuery);
gs.print('TOTAL COUNT::' + iCount);

function _countRecords (gr_records, gr_query) {

        var ga = new GlideAggregate(gr_records);
        //--https://developer.servicenow.com/dev.do#!/guides/sandiego/now-platform/tpb-guide/scripting_technical_best_practices
        ga.addAggregate('COUNT');
        ga.addQuery(gr_query);
        ga.query();

        var count = 0;
        if (ga.next())
            count = ga.getAggregate('COUNT');

        return count;
    }

Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage