Script to update the operational status field of cmdb_ci_computer table to retired

Arathi B Raj
Mega Contributor

We were trying to run the BG script below to change the operational status of some computers to retired where discovery source is from SCCM and most recent discovery is before Aug 1 2022-

var gr= new GlideRecord("cmdb_ci_computer");
gr.addQuery('discovery_source','SG-SCCM');
gr.addQuery('last_discovered','<','2022-08-01 00:00:00');
gr.addQuery();
while (gr.next()){
    gr.setValue("operational_status",5);
    gr.update();
}

But this was not working.

Can anyone point out what could be wrong here or anyone who can help with a script to achieve this requirement.

9 REPLIES 9

Hi Ankur

Need a favour please.

I have 966 servers in Excel file and need to bulk update Operational Status = Retired.

Appreciate if you can share the script please.

Thank you in advance

@NH2 

you should use data load, transform map for this

Please post a new question and add any issues faced there

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

Hi Ankur

Thanks for the reply! It helped.

Can we get to know how does the below script line suggested by you change, if we want to query for not discovered in last 30 days (i.e most recent discovery > 30 days )

gr.addEncodedQuery("last_discovered<javascript:gs.dateGenerate('2022-08-01','00:00:00')");

 

Thanks & Regards

Arathi Raj

Hi,

Glad to know that my script helped.

Would you mind marking my response as correct and close the thread.

Regards
Ankur

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

@Arathi B Raj 

like this form the filter and copy the query

last_discoveredNOTONLast 30 days@javascript:gs.beginningOfLast30Days()@javascript:gs.endOfLast30Days()

find_real_file.png

Regards
Ankur

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