- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 06:26 AM
Hi All,
As I am beginner in coding I am not able to fetch choices option in for loop when using JSON.parse(answer); Getting wrong result(below) in comma separated and in single line. It should be like options.
How to achieve it? Please let me know what to modify in my code. Here is my code below:
var obj = JSON.parse(answer);
alert(answer);
g_form.clearOptions('u_service_name');
for(var i=0; i<obj.length; i++)
{
g_form.addOption('u_service_name', obj[i],obj[i]);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 07:07 AM
try now.
var ci = this.getParameter('sysparam_caller');
var gr = new GlideRecord('u_cx_service_name');
gr.addQuery('u_configuration_item', ci);
gr.query();
var arrReturn = [];
while (gr.next())
{
var obj = {};
obj.lab = gr.getDisplayValue('u_service_names'),
obj.val =gr.getValue('u_service_names')
arrReturn.push(obj);
}
return JSON.stringify(arrReturn);
var obj = JSON.parse(answer);
alert(answer);
g_form.clearOptions('u_service_name');
for(var i=0; i<obj.length; i++)
{
g_form.addOption('u_service_name', obj[i].val,obj[i].lab);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 06:48 AM