Client Script - setValue not working as expected

Sue Frost
Giga Guru

I have an OnLoad client script to set a choice list field and then set the actual value of the field.

The choices are dynamic and are first looked up (when another reference field is entered) and then stored in a field to feed the choice list.

The choice values are being correctly returned and the options in the choice list are being set. However, if a value in the field exists, when reloading the form, only the value is shown, not the display value:

9-7-2017 1-17-44 PM.png

Here's my client script:

function onLoad() {

//Type appropriate comment here, and begin script below

//Build Coverage Item Description Code choice list

var covCodes = g_form.getValue('coverage_code_options');

var covNum;

var currValue = g_form.getValue('coverage_item_description_code');

g_form.clearValue('coverage_item_description_code');

alert('currValue - ' + currValue);

if(covCodes == ''){

return;

}

var codeChoices = covCodes.split(',');

var i = 0;

for(i = 0; i < codeChoices.length; i++) {

covNum = codeChoices[i].split(' - ');

g_form.addOption('coverage_item_description_code', covNum[0], codeChoices[i].toString(), covNum[0]);

if(currValue == covNum[0]){

alert("into IF - " + covNum[0] + " - " + codeChoices[i].toString());

g_form.setValue('coverage_item_description_code', covNum[0], codeChoices[i].toString());

}

}

}

The alerts show me that I AM getting the correct values (5 and 5 - TOOLS in my example) but I can't get the field to show "5 - TOOLS" That should, as far as I can tell, be what line 27 does. What am I doing wrong?

TIA!

1 ACCEPTED SOLUTION

saprem_d
Giga Guru

Hi,



Can you try updating line   29 as below



g_form.setValue('coverage_item_description_code', codeChoices[i].toString());


View solution in original post

6 REPLIES 6

Further, please use g_form.clearOption() instead of clearValue()


I've tried     g_form.clearOptions('coverage_item_description_code');     and it's removing the number only but leaving a duplicate of the '5 - TOOLS' choice.


I think that will be sufficient but it's still not totally correct.