How to update list value in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 02:23 AM
How to update list field using background script, will set value will work here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 02:43 AM
as sudhanshu already pointed next()
var com = new GlideRecord('core_company');
com.addQuery('name','ACME Australia');
com.setLimit(1);
com.query();
while(com.next()){
com.u_type = "00aba08d3790200044e0bfc8bcbe5dfc";
com.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 02:41 AM
while(com.next())
{
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 02:42 AM
good catch 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 02:35 AM
Oh I see you wanted it in a background script:
var valuesToSet = [];
var table = ''; //fill in the table
var sysID = ''; //fill in the sys id of the record you want to update
valuesToSet.push(current.assigned_to.toString());//example to add assigned to
valuesToSet = new ArrayUtil().unique(valuesToSet);
var gr = new GlideRecord(table);
if (gr.get(sysID)) {
gr.u_test = valuesToSet.toString();
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 04:35 AM
I want to update watch list from scripted rest api. Can you help me with script. I am not getting how to update it in the list