Page 1 of 1

Conditional Drop Downs

Posted: 23 Apr 2019
by Adam Reyes
Hello,

I've used the following conditions before in forms but for some reason it doesn't seem to be working anymore. The following code continues to give me a return of "OSI" no matter which selection I choose. Is there something you can see wrong with the conditional code below?

fd.field('ContractsCAGECode').control().change(function(){
var cagecode = fd.field('ContractsCAGECode').control().value();

if (fd.field('ContractsCAGECode').control().value() == '1VZN4')
{
fd.field('Entity').control().value("AI");
}
else if (fd.field('ContractsCAGECode').control().value() == '5UBL3')
{
fd.field('Entity').control().value("ATG");
}
else if (fd.field('ContractsCAGECode').control().value() == '59W37')
{
fd.field('Entity').control().value("Stratus");
}
else (fd.field('ContractsCAGECode').control().value() == '097A3')
{
fd.field('Entity').control().value("OSI");
}
});

Re: Conditional Drop Downs

Posted: 26 Apr 2019
by AlexZver
Dear Adam,

I'm sorry for a late reply. Correctness depends on what type the field is. If the field is a Choice field than the code is correct, but if the field is a Lookup than control().value() returns Id of the lookup item and not the text: https://spform.com/javascript-framework ... eld-values

If the field is a lookup field, please, try to use the code below:

Code: Select all

fd.field("Lookup").control('getSelectedText')

Re: Conditional Drop Downs

Posted: 26 Apr 2019
by Adam Reyes
Hi Alex,

The fields are both drop-down fields but for some reason this code doesn't seem to work so I've had to make a function for every single value which doesn't seem to be the ideal way to do it. Any thoughts on why the code wouldn't work for drop-down fields?

Re: Conditional Drop Downs

Posted: 29 Apr 2019
by AlexZver
Hi Adam,

Please try to complete your code with the "debugger;" option. Place it right in your code before the problem part, save the form, then open the form in browser with the browser console (F12). The code execution will stop on the "debugger;" command, so you will be able to test your code more properly in the browser console.