Background script to replace old glide_list entries

SC10
Kilo Guru

On my Project table, I have a glide_list field that is referencing a now deleted reference entry (now displays as a sys_id). I've been able to query for all Projects that contain this entry in that field, but I'd like to use a background script to replace this sys ID entry with a different value. Any help is appreciated.

Thank you

1 ACCEPTED SOLUTION

Daniel Draes
ServiceNow Employee
ServiceNow Employee

I would use the ArrayUtil-Script include to parse the current values of your glide_list to an array. Also in ArrayUtil you can do the search to find the proper place of the old value and replace it.

 

Other option - since a glide_list is just a comma-separated string - is a simple replace command. I.e.

 

var my_list_string = gr.some_field + ''; // adding an empty string to force type conversion

my_list_string.replace(old_sys_id, 'New value');

gr.some_field = my_list_string:

gr.update();

View solution in original post

6 REPLIES 6

Got it working with some HI support staff help that I kicked off before this forum post... had to change:

 

my_list_string.replace(old_sys_id, 'New value');

to be

my_list_string = my_list_string.replace(old_sys_id, 'New value');

Nikhil Dixit
Giga Expert

Hi,

 

ArrayUtil API is a script include with useful functions for working with JavaScript arrays. In this case first parse  the current values of your glide_list to an array then use replace() method to replace the new value from old value.

 

Thanks,

Nikhil Dixit