- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:12 AM
Hi All,
Please find the below script.I want to clear 'assigned to' field from 20k records,for that I need a script that will take 500 or 1000 records at a time .I have Used the function setLimit , but when running the script it is clearing the value from all records irrespective of the limit I have given. Can anyone please check on this.
var queryString = "hardware_status=retired^assigned_toISNOTEMPTY";
var asset= new GlideRecord('cmdb_ci_computer');
asset.addEncodedQuery(queryString);
asset.query();
while(asset.next())
{
gs.log('asset record cleared : '+asset.serial_number);
asset.setLimit(500);
asset.assigned_to="";
asset.update();
}
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:14 AM
I believe your setLimit() needs to be before the asset.query(); line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:15 AM
Hi Asha,
setLimit() should be used before query and not while updating.
update your code as below
var queryString = "hardware_status=retired^assigned_toISNOTEMPTY";
var asset= new GlideRecord('cmdb_ci_computer');
asset.addEncodedQuery(queryString);
asset.setLimit(500);
asset.query();
while(asset.next())
{
gs.log('asset record cleared : '+asset.serial_number);
asset.assigned_to="";
asset.update();
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
09-26-2018 07:40 AM
Thank you..it is working 🙂