- 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 11:04 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.setWorkflow('false');
gr.updateMultiple();
is this script correct now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 11:05 PM
Hi,
looks fine
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader