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

Brian Lancaster
Tera Sage

You may want to add an index field to you addOpation

g_form.addOption('u_phone_number_line', 'MPhone', 'MPhone', 1);
g_form.addOption('u_phone_number_line', 'BPhone', 'BPhone', 2);
g_form.addOption('u_phone_number_line', 'line1', 'line1', 3);
g_form.addOption('u_phone_number_line', 'line2', 'line2', 4);
g_form.addOption('u_phone_number_line', 'line3', 'line3', 5);
g_form.addOption('u_phone_number_line', 'line4', 'line4', 6);
g_form.addOption('u_phone_number_line', 'line5', 'line5', 7);

also if you ever want to make this filed mandatory are you are not using Service Portal you probably want to add none option.

g_form.addOption('u_phone_number_line', '', '-- None --', 0)

No it is not working still having same issue if i include none option in top then its showing none option only.

Are these options in your choice list and you are only trying to display them if a certain condition occurs?

No,There is string field which is in different table(contract) and from that table we want to fetch the value and display as a choice in current table.