
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 08:34 AM
Looking for example scripts for removing the assigned to value from 25k asset records. It was assigned by mistake and I am looking for a background script that can change the value to NULL.
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 09:35 AM
You did test with sys_id you mentioned? Because assigned_to is a reference.
Though looking at your script now... updateMultiple will not work, because... you are querying on assigned_to, and then emptying assigned_to? With a while this would be possible, though not with updateMultiple.
Unfortunately, a while is looking at performance really bad. Though querying on the asisgned_to and then emptying this, will just not work with update multiple. So, unfortunately:
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', 'ce826bf03710200044e0bfc8bcbe5d79');
gr._query();
while(gr._next()) {
gr.setValue('assigned_to', '');
gr.setWorkflow(false);
gr.update();
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
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
09-12-2019 08:37 AM
You can use GlideRecord.updateMultiple for it (see example). You can edit the encoded query, if you wish to.
var grAsset = new GlideRecord('alm_asset');
grAsset.addEncodedQuery('assigned_toISEMPTY');
grAsset.query();
grAsset.setValue('assigned_to', '');
grAsset.updateMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 08:49 AM
Hi Bowden,
Use fix script for this and as best practice use try catch block for exception handling
Will you be querying for all records where assigned_to is not empty?
Did assigned_to get assigned by mistake to all records or only 25k? What is the table record count?
clearValue();
function clearValue(){
try{
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', '!=', '');
gr.query();
while(gr.next()){
gr.assigned_to = '';
gr.setWorkflow(false);
gr.update();
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
}
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-12-2019 08:53 AM
just the 25k as the asset record count is 400K+