Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to get list field values (multiple) of form in Client Script ?

Ankita Misstry
Kilo Contributor

Hello ,

I am new to servicenow. I am trying to get all form data in client script on-load event. I have created custom table and  custom form. Now i have added list field where i can select multiple incident numbers. I want these numbers on-load client script. I have selected 3 incident numbers and i am getting 3 sys_id when i tried to getvalue.  What should I do ?

var inciNumbers = g_form.getValue('u_incident_number');
alert(inciNumbers);

It gives me 3 sys_ids. Not incident numbers.

Please check attached screen,

find_real_file.png

 

Please help. Thanks !

2 REPLIES 2

Not applicable

The value of a list field is a list of sysid's, so when you do getValue on that field you will get a result like this 

['d37aaa42d7330200a9addd173e24d460','d37aaa42d7330200a9addd173e24d460','d37aaa42d7330200a9addd173e24d460']

If you wish to get the incident numbers, get the references from these values, and then get the number.

This code is an example, and may not be 100% perfect, but it will be similar if it doesn't work.

var inclist = g_form.getValue('u_incident_number');
var numberlist = [];
var records = new GlideAjax("incident");
records.addQuery("sys_id","IN",inclist);
records.query();
while(records.next()){
  numberlist.push(records.getValue("number"));
}
alert(numberlist);

Prateek kumar
Giga Sage

Try this with a combination of Display Business rule and OnLoad Client script

1. Configure a Display Business rule on your custom table.

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

	var incNumbers = [];
incNumbers.push(current.u_incident_number.getDisplayValue().toString());


	g_scratchpad.incNumber = incNumbers;


})(current, previous);

2. OnLoad Client Script.

function onLoad() {
alert(g_scratchpad.incNumber);
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks