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

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

why not use scheduled flow for this and no scripting required?

simply use Lookup Records on that table with conditions as Updated Before 7 Days

If you still require scheduled job then here is the sample script, please enhance

(function() {
    var gr = new GlideRecord('cmdb_software_instance');
    var sevenDaysAgo = gs.daysAgoStart(7);
    gr.addQuery('sys_updated_on', '<', sevenDaysAgo);
    gr.query();
    while (gr.next()) {
        gr.setValue('install_status', 'retired'); // Assuming 'retired' is the correct status value
        gr.update();
    }
})();

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

HI @Ankur Bawiskar ,

 

Thanks for the response,

 

I tried but it is not working, actaully in the software instances table we have only this fields and instal status is present in installed on 

suuriyas_0-1744701876633.png

 

can you help me modifying this

(function() {
    var gr = new GlideRecord('cmdb_software_instance');
    var sevenDaysAgo = gs.daysAgoStart(7);
    gr.addQuery('sys_updated_on', '<', sevenDaysAgo);
    gr.query();
    while (gr.next()) {
        gr.setValue('install_status', '7');
        gr.update();
    }
})();

 

@suuriyas 

I just provided sample script, you can enhance it further

do you want to query "cmdb_software_instance" or "software" table?

It's up to you but the logic for 7 days I already shared

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

@suuriyas 

what's your actual requirement?

since your table "cmdb_software_instance" gets updated daily, are you saying if there is no record in this table for any software then that software record you need to update?

Remember there are 3 tables involved "cmdb_software_instance", "cmdb_ci" and "cmdb_ci_spkg"

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