- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:47 PM
hi all,
i have a requirement where i have 20 lakh records. and of those 20 lakh records, i have to change to operational status field value to non-production. below is the code that i have written. can any1 suggest me a better way.
var gr=new GlideRecord('cmdb_ci');
gr.addEncodedQuery('discovery_source=Altiris');
gr.setLimit(20000);
gr.query();
while(gr.next())
{
gr.setValue('operational_status',2);
gr.update();
}
i will be adding it to a schedule job and will be running it on demand. but if i am using a setlimit of 20k. so when first the job ran, it updated 20k records. when i will be running it again, how will the job know that i have to skip the 20k which i updated recently and do update on the remaining (20lakh-20k records)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:50 PM
Hi,
ensure you add the query for operation status
var gr=new GlideRecord('cmdb_ci');
gr.addEncodedQuery('discovery_source=Altiris');
gr.addEncodedQuery('operational_status!=2');
gr.setLimit(20000);
gr.query();
while(gr.next())
{
gr.setValue('operational_status',2);
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:50 PM
Hi there,
Have you considered using updateMultiple() instead of update()?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:50 PM
Hi,
ensure you add the query for operation status
var gr=new GlideRecord('cmdb_ci');
gr.addEncodedQuery('discovery_source=Altiris');
gr.addEncodedQuery('operational_status!=2');
gr.setLimit(20000);
gr.query();
while(gr.next())
{
gr.setValue('operational_status',2);
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:52 PM
Hi,
to make it faster you can use updateMultiple() and also use setWorkflow(false) in case you wish to block the business rules on table from running on update
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 11:00 PM
var gr=new GlideRecord('cmdb_ci');
gr.addEncodedQuery('discovery_source=Altiris');
gr.addEncodedQuery('operational_status!=2');
gr.setLimit(20000);
gr.query();
gr.setValue('operational_status',2);
gr.updateMultiple();
gr.setWorkflow('false');
is this script correct now?
and do i need to write gr.query()?