ServiceNow get oldest record in a table, and check if it's > 6 months old

 

var lastUpdated=getLatestRecord('azure_billing_table'); var luDate=(new GlideDateTime(lastUpdated)); gs.print('lastUpdated='+luDate); gs.print(luDate < gs.monthsAgoStart(6)) gs.print(luDate > gs.monthsAgoStart(6)) function getLatestRecord(tableName){ var dReturn; var gr = new GlideRecord (tableName); gr.orderByDesc('sys_created_on'); gr.setLimit(1); gr.query(); if (gr.next()){ dReturn=gr.sys_created_on; } return dReturn; }

Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage