Why g_form.clearValue() not working in portal for select box variable type?

Ankita Kolhe
Tera Contributor

Hi Community,

 g_form.clearValue() not working in portal for select box variable type in on change client script.

 

Please find the screenshot & code below:-

 

AnkitaKolhe_0-1680092895008.png

 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var leadCountry = g_form.getValue('u_lead_country');
var fun = g_form.getValue('u_function');
var globalInvAjax = new GlideAjax('GlobalInvestment');
globalInvAjax.addParam('sysparm_name', 'getAccountsData');
globalInvAjax.addParam('sysparm_accountid', newValue);

globalInvAjax.getXMLAnswer(function(response) {
var count2 = 0;
var invProgram=[];
var answer = response;
var accounts = JSON.parse(answer);

if (fun != '' && accounts.pathTo100 == 'yes' && newValue == 'USA') {
invProgram.push('Path to 100');
}

if (fun != '' && leadCountry != '' && accounts.accountType=='Non-Audit' &&(accounts.globalAccount == 'Other Global Platinum' || accounts.globalAccount == 'Tech Priority')) {
invProgram.push('Levy funded program');
}

if (fun != '' && leadCountry != '' && accounts.globalAccount == 'Chairman' + '\'s' + ' Accounts') {
invProgram.push('Accelerated growth program');
}

if (fun == 'advisory' && leadCountry != '' && leadCountry != 'USA' && (accounts.globalAccount == 'Other Global Accounts' || accounts.globalAccount == '')) {
invProgram.push('Advisory dynamic client program');
}

if(invProgram.length==2){

g_form.clearOptions('u_funding_business_group');
g_form.clearValue('u_funding_business_group');

if(invProgram[0]=='Path to 100' || invProgram[1]=='Path to 100')
g_form.addOption('u_funding_business_group','path to 100','Path to 100');
if(invProgram[0]=='Levy funded program' || invProgram[1]=='Levy funded program')
g_form.addOption('u_funding_business_group','levy funded program','Levy funded program');
if(invProgram[0]=='Accelerated growth program' || invProgram[1]=='Accelerated growth program')
g_form.addOption('u_funding_business_group','accelerated growth program','Accelerated growth program');

alert(invProgram[0] + ' '+invProgram[1]);
}
else if(invProgram.length==1){
alert(invProgram[0]);
g_form.clearOptions('u_funding_business_group');
g_form.setValue('u_funding_business_group',invProgram[0]);
}


});

}

 

 

Thanks,

Ankita

2 REPLIES 2

Michael Jones -
Giga Sage

Does the field keep it's original value, or does it end up having the first value that you are setting with addOption?

You might try clearing the value first, before you remove the options if it is retaining the original value, otherwise, you would want to be sure that the first option you are passing in has a value of '' (usually a label of '--None--') otherwise the select box will always have a default value of the first available options. That's why "include none" in an option for static lists. 

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Aziz GUEYE
Tera Contributor

Use this alternative

g_form.setValue("variable_name", []);

Please check and let me know if still facing the issue.