- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2022 10:35 AM
Hi,
I'm populating a select box (database name) based on the application selected in the catalog item using client and script include. After submitting the catalog item, the select box is empty and when I click on it, it shows the option I have selected. Used the similar script for many other catalog items and its working fine. See this issue only for this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideAjax('getDb');
gr.addParam('sysparm_name','getDb1');
gr.addParam('sysparm_appName', g_form.getValue('app_name').toString());
gr.getXML(getdataname);
function getdataname(response){
g_form.clearOptions('u_dbName');
g_form.addOption('u_dbName','','---None---');
var msg = response.responseXML.documentElement.getAttribute("answer").split(',');
if(msg == ''){
alert('xxx');
g_form.clearValue('appName');
g_form.clearValue('appId');
g_form.clearValue('appLead');
}
else{
for(var i=0;i<msg.length;i++)
{
g_form.addOption('u_dbName',msg[i], msg[i]);
}
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:44 AM
I have set the field 'clear variable name' to true in a UI policy by mistake. Set it to false and its working now. Thanks everyone for the inputs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2022 10:45 AM
Hi,
have you checked what value your getting in msg[i] ? Because it should be string value, check msg[i] in alert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2022 01:12 PM
Hi, I'm receiving the expected values in msg[i]. The issue is field is showing empty value after submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 02:57 AM
Hi,
As you have mentioned, when you click, it shows the option you had selected.So you can try out below suggestion.
While adding the options via addOption method, add another parameter named targetIndex which will ensure the position of the choice.
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
targetIndex will be a numeric value starting with 0. so you can choose to map '-None-' with 0th position.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 03:05 AM
Hi,
Ensure your catalog client script doesn't run on Requested Item record
Applies to Requested Item Checkbox should be Unchecked
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader