Select box empty after submitting the catalog item

redth
Giga Expert

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]);
}
}
}
}

1 ACCEPTED SOLUTION

redth
Giga Expert

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.

View solution in original post

5 REPLIES 5

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi,

          have you checked what value your getting in msg[i] ? Because it should be string value, check msg[i] in alert

    

Hi, I'm receiving the expected values in msg[i]. The issue is field is showing empty value after submission

 

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.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Ensure your catalog client script doesn't run on Requested Item record

Applies to Requested Item Checkbox should be Unchecked

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader