Need a schedule job to retire the record

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, the software instances (cmdb_software_instance) table will be updating on the daily basics in our system. Now I need to write a schedule job to retire the software data/records which are not updated for the last 7 days.

 

How can we achieve this

11 REPLIES 11

@suuriyas 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

virajtodkar
Tera Expert

Hi @suuriyas ,
You can use Schedule Job with with Run Weekly,
Code:

var retireSoftware = new GlideRecord('cmdb_software_instance');
retireSoftware.addEncodedQuery('sys_updated_on<javascript&colon;gs.beginningOfLast7Days');
retireSoftware.query();
while(retireSoftware.next()){
    retireSoftware.status='retired'; /// Assuming status is correct field and 'retired' is value
    retireSoftware.update();
}