How to update list value in servicenow

Sathwik1
Tera Expert

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

find_real_file.png

14 REPLIES 14

Harsh Vardhan
Giga Patron

You can try with below code.

 

var gr = new GlideRecord('<table name>');

gr.get('<sys id of record>'); // for an example

gr.<list field name>= 'sys_id of that value'; // list type accept sys_id because it refer to a table.

gr.update();

Willem
Giga Sage
Giga Sage

Yes, just use a String of comma separated values.

So something like this:

(function executeRule(current, previous /*null when async*/) { 

    var valuesToSet = [];
    valuesToSet.push(current.assigned_to.toString());//example to add assigned to
    valuesToSet = new ArrayUtil().unique(valuesToSet);
    current.u_test = valuesToSet.toString();

 })(current, previous);

Sudhanshu Talw1
Tera Guru

Yes just like you set reference value do it here via GlideRecord. It will work.

 

Thanks

Sudhanshu

Jaspal Singh
Mega Patron
Mega Patron

Hi Sathwik,

 

Insteas of background script did you try editing it from list view?

If you tried & it did not work then it is because of system property: glide.ui.list_edit_ignore_types

Look for the property from System properties table & remove the 'list' from the Value field.

Once done try editing/updating records from List view & it should work.

Since, it a global property modifying it would mean it make fields of type List to be editable across tables.