Skip to main content
November 2, 2017
Answered

Custom If formula and dropdown lists.

  • November 2, 2017
  • 1 reply
  • 737 views

Hi.

I'm trying to create a form pdf with a dropdown option (field named "CarClav"). Currently, the list has 6 options, plus one blank default option.

I'm trying to configure it so it writes in another field ("ModCar") a number that is on diferent fields, depending on the option selected on the list.

Example:

If "CarClav" is "Fue", write the value of the field "ModFue" on the "ModCar" field.

If "CarClav" is "Des", write the value of the field "ModDes" on the "ModCar" field.

If "CarClav" is "Sab", write the value of the field "ModSab" on the "ModCar" field.

Currently, I've solved most of this, I guess. My code looks like this (CustomKeystrokeScript on the Format tab)

if(event.willCommit)

{

console.println(event.value);

    switch(event.value)

    {

         case "FUE":

                this.getField("ModCar").value = 1;

                break;

         case "DES":

                this.getField("ModCar").value = 2;

                break;

case "CON":

                this.getField("ModCar").value = 3;

                break;

case "INT":

                this.getField("ModCar").value = 4;

                break;

case "SAB":

                this.getField("ModCar").value = 5;

                break;

case "CAR":

                this.getField("ModCar").value = 6;

                break;

default:

                this.getField("ModCar").value = "";

                break;

 

    }

}

[Note: emphasis was added where the problem is. I would like to change the results (1-6) to the value of respective fields, as noted before]

Thank you!

This topic has been closed for replies.
Correct answer try67

Replace this:

this.getField("ModCar").value = 1;

With:

this.getField("ModCar").value = this.getField("ModFue").valueAsString;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 2, 2017

Replace this:

this.getField("ModCar").value = 1;

With:

this.getField("ModCar").value = this.getField("ModFue").valueAsString;

November 3, 2017

Thank you very much!

It does work. However, I found a little problem: when I set the value to Fue, it returns the value of the correct field, however, if that value changes later, the ModCar doesn't change, it keeps showing the old value.

Any ideas?

try67
Community Expert
Community Expert
November 3, 2017

You should change your code to be a custom calculation script of ModCar.