Getting by default first value using addOption();

Pragati4
Tera Contributor

Hi Team

I don't know why in form i am getting by default first value only but in list view i am getting correct value.

For reference please find the below script, please let me know what i am missing in this and how to avoid incorrect value inside the form.

Because in this script i am giving first option as "MPhone" so after saving the form it will show me MPhone number only instead of correct choice which I made before saving the form.

 

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

//Type appropriate comment here, and begin script below
g_form.getReference('contact',callbackfun);
function callbackfun(contact){
var BPhone = 'Business Phone'+'-'+contact.phone ;
if(contact.u_extension)
{
BPhone = BPhone +' x'+contact.u_extension;
}
var MPhone = 'Mobile Phone'+'-'+contact.mobile_phone;
var line1 = contact.u_phone1_label+'-'+contact.u_phone1_value;
var line2 = contact.u_phone2_label+'-'+contact.u_phone2_value;
var line3 = contact.u_phone3_label+'-'+contact.u_phone3_value;
var line4 = contact.u_phone4_label+'-'+contact.u_phone4_value;
var line5 = contact.u_phone5_label+'-'+contact.u_phone5_value;

if(g_form.getValue('u_internal_cont_select') != true){
g_form.clearOptions('u_phone_number_line');

g_form.addOption('u_phone_number_line', MPhone, MPhone);
g_form.addOption('u_phone_number_line', BPhone, BPhone);
g_form.addOption('u_phone_number_line', line1, line1);
g_form.addOption('u_phone_number_line', line2, line2);
g_form.addOption('u_phone_number_line', line3, line3);
g_form.addOption('u_phone_number_line', line4, line4);
g_form.addOption('u_phone_number_line', line5, line5);
}
}
}

5 REPLIES 5

I don't think it will work that way.  I think you need to have the choices in your choice field and they do a clear option then add option to add back in the ones you want to display depending on your other conditions.