How to get list field values (multiple) of form in Client Script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2019 02:42 AM
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,
Please help. Thanks !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2019 05:32 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2019 05:56 PM
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