logo

NJP

Get last updated Date record using GlideAggregate

Import · Jun 12, 2020 · article

Get last updated Date record using GlideAggregate

var aggIncident = new GlideAggregate('incident');
aggIncident.addAggregate('MAX', 'sys_created_on');
aggIncident.groupBy('priority');
aggIncident.query();

while(aggIncident.next()){


//get the first record, this should be the latest


dtLastUpdate = aggIncident.getAggregate('MAX','sys_created_on');


gs.log('number=' +aggIncident.number + ' pri ' + aggIncident.priority + ' dtLastUpdate ' + dtLastUpdate);

}

Sample results

*** Script: number= pri 1 dtLastUpdate 2020-01-20 12:32:05*** Script: number= pri 2 dtLastUpdate 2020-01-20 12:31:29*** Script: number= pri 3 dtLastUpdate 2020-02-13 13:49:40*** Script: number= pri 4 dtLastUpdate 2020-01-20 12:30:40

*** Script: number= pri 5 dtLastUpdate 2020-06-10 19:16:17

image

Script summary

Scripts - Oficial Doc.

Discovery

Versões do ServiceNow

Como testar / debugar o seu script?

Create default filter for a related list

View original source

https://www.servicenow.com/community/developer-articles/get-last-updated-date-record-using-glideaggregate/ta-p/2321818