Skip to main content
Alliosaaa
Inspiring
January 24, 2019
Answered

What is wrong with this code?

  • January 24, 2019
  • 1 reply
  • 1310 views

Hi there!

The ultimate goal of this script is to set various field values throughout a form depending on what branch is chosen from a radio button group on the first page. I'm testing out the functionality with just two attributes - location name and address.

In my tests, I selected "KBAN" as my location and ran this in the console. It did not set the field values of ("LOCATION_NAME") and ("LOCATION_ADDRESS"), but it did return "321 XYZ Road" in the console window.

Any ideas why it won't set the field values?

Thank you!

var Location = this.getField("LOCATION").valueAsString; //radio button group

var arrLocations = ["KPOR",

                    "KBAN",

                    "KCON",

                    "KBUR",

                    "KRUT"];

var locIndex = arrLocations.indexOf(Location);

var arrName = ["Portland",

               "Bangor",

               "Concord",

               "Burlington",

               "Rutland"];

var arrAddress = ["123 ABC Road",

                  "321 XYZ Road",

                  "345 Any Road",

                  "543 Some Road",

                  "567 Another Road"];

var name = this.getField("LOCATION_NAME").value;

var address = this.getField("LOCATION_ADDRESS").value;

var arrFldAttributes = [name,

                        address];

var arrAttributeVals = [arrName,

                        arrAddress];

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

     arrFldAttributes = arrAttributeVals[locIndex];

}

This topic has been closed for replies.
Correct answer Bernd Alheit

I've defined those as the variables "name" and "address" in lines 23 and 24. Shouldn't the array defined on line 26 point to those values to set?


There you have saved the old values of the fields.

And with

arrFldAttributes =

you change only the values in this array.

1 reply

Bernd Alheit
Community Expert
Community Expert
January 24, 2019

Where did you set the field values?

Alliosaaa
AlliosaaaAuthor
Inspiring
January 24, 2019

The purpose of the loop at the end is to set the field values.

arrFldAttributes is an array of the fields whose values I want to set, and arrAttributeVals is an array of arrays containing the values the fields should be set to.

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

     arrFldAttributes = arrAttributeVals[locIndex];

}

I'm sure I'm missing something simple here - just can't figure out what it is!

Thank you!

Bernd Alheit
Community Expert
Community Expert
January 24, 2019

There must be something like:

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

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