Remove a specific value from a glide_list field

LdR
Tera Expert


Hello,
I have a glide_list field

find_real_file.png

from which, after pressing a button (UI Action), I want to remove a certain value.

How could I do?
Thanks ☺

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Use following script. when you use g_form or current on the glide list field it will return comma separated sys_ids. you need to know which value or sys_id to remove so that you can again set the value in the field.

var arr = ['1','2','3'];

var toBeRemoved = 1;

var tempArr = [];

for(var i=0;i<arr.length;i++){

if(arr[i] != toBeRemoved)
tempArr.push(arr[i].toString());

}

gs.print(tempArr);

use this tempArr to set the value in the glide list again and save the record if you want

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the code Ankur, this helped me a ton!

Hi Drew,

Can you also mark the answer as correct and helpful. Thanks in advance.

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I wasn't the original poster, but I appreciate the help!