We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to update list value in servicenow

Sathwik1
Tera Guru

How to update list field using background script, will set value will work here?

find_real_file.png

14 REPLIES 14

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();
}

while(com.next())

{

}

good catch 🙂

Willem
Giga Sage

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();
}

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