- 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-06-2019 09:31 AM
Hi Harshavardhan,
You are great!! Its working 🙂 thank you so much your help 🙂 ... But one thing i need to ask ...in choice list i am not getting --None-- value. Its coming as empty. see the screenshot.
Regarding,var ci = this.getParameter('sysparam_caller'); ..as u suggested I tried sysparm_caller also. but its giving null value. So i didn't update it
I am concerned about one more thing...I selected any choice options and save the form. After that rest of the options are vanished.Only selected option and None is there in choice lists... please see the screenshot below:
If user want to again update any choice option?
Thanks,
Swathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 09:42 AM
if you are adding those option using client script then it wont be available after saving the form. client script is just for form .
eg: if you seeing 2 drop down values and selected one , that will be only available after saving the form other will be vanished.
if i am not wrong you client script is working on field change so you can run your script on load as well.
just comment the below line in your client script then those option will be available on form load.
// if (isLoading || newValue === '') {
// return;
// }
can you confirm in the field dictionary you have selected the choice as "drop down with None"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 10:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 10:51 PM
I tried to update service name field to "drop down with None" as well as "drop down without None" but an empty space is coming in choice list which should not be there. Please tell me what I need to change in code.
thanks,
swathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2019 11:07 PM
can you confirm, on "u_service_names", how many number of values stored ? is it also storing blank value ?