g_form.addOption() is not working inside GlideAjax callback function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a MRVS have a field have type is Select Box, in my onLoad client script have a callback function in GlideAjax to get question choice in order to add options to select box field. I tried to log the response and it working correctly. but when I call g_form.addOption() outside the callback function then the option is added correctly but when I tried to call it inside the callback function it is not working. Please help.
//old options is cleared before this line
var optionAjax = new GlideAjax('scoped_app.script_include');
optionAjax.addParam('sysparm_name', 'functionname');
optionAjax.addParam('sysparm_question_id', varId);
// g_form.addOption('value_select_box', choiceValue, choiceLabel); this line work correctly but the addOption line below is not
optionAjax.getXMLAnswer(function(response) {
var res = JSON.parse(response); //[{'option_value':'value', 'option_text':'text'}]
for (var i = 0; i < res.length; i++) {
var choiceValue = res[i].option_value+'';
var choiceLabel = res[i].option_text+'';
g_form.addOption('value_select_box', choiceValue, choiceLabel);
//I also tried g_form.addOption('value_select_box', choiceValue, choiceLabel, i+1); but still not working
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi ,
There are a couple of things I’d like to validate before answering:
- Is
value_select_boxthe internal variable name? - Do you see any errors in the browser console when the page loads or when you perform the action with F12 Developer Tools open?
Kind regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
1. value_select_box is the internal variable name
2. There is no browser error when the page is load
In addition, i want the options to be add correctly on workspace, but when i tried to perform the action in ClassicUI the issue still happened
Thanks so much,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @HoangT551406063 ,
Are you sure all the values you passed to Add Option are strings?
Is your script placed within MRVS?
Did you set UI type to All?
Did you set checkbox "apply on catalog item" to active?
kind regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hii @An Le,
I log all and check all the condition of the script, value passed to addOption is string, all the script is working correctly except the addOption
