Add value to list variable in client script

msrishilpa
Mega Expert

Hi,

 

please let me how to add values in to list variable in client script.

2 REPLIES 2

PeterWiles
Kilo Sage

The list variable is just a comma separated list of values so to add a value, either just make the variable equal to something


g_form.setValue("list", "red,blue,green");


or add in an additional value with


var list = g_form.getValue("list");


list += "yellow";


g_form.setValue("list", list);



See the wiki for details. GlideForm (g form) - ServiceNow Wiki


The question is why do you want to do it via Client Script versus populating the values from a table? From the maintenance perspective, every time you need to change or add new values to the list, you will have to touch the client script, versus doing it via data maintenance on the table.


I am just curious ....