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;
}
Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g. var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ()) option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){
Comments
Post a Comment