Copy link to clipboard
Copied
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];
}
There you have saved the old values of the fields.
And with
arrFldAttributes =
you change only the values in this array.
Copy link to clipboard
Copied
Where did you set the field values?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
There must be something like:
this.getField("LOCATION_NAME").value = ... ;
this.getField("LOCATION_ADDRESS").value = ... ;
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
There you have saved the old values of the fields.
And with
arrFldAttributes =
you change only the values in this array.
Copy link to clipboard
Copied
Thank you - I totally understand now!
Made some adjustments to the end of the code and it's now working:
var arrFldAttributes = ["NAME",
"ADDRESS"];
var arrAttributeVals = [arrName,
arrAddress];
for (i=0; i < arrFldAttributes.length; i++) {
this.getField("LOCATION_" + arrFldAttributes).value = arrAttributeVals[locIndex];
}
Copy link to clipboard
Copied
Or you can use something like this:
var arrFldAttributes = ["LOCATION_NAME", "LOCATION_ADDRESS"];
var arrAttributeVals = [arrName,
arrAddress];
for (i=0; i < arrFldAttributes.length; i++) {
this.getField(arrFldAttributes).value = arrAttributeVals[locIndex];
}
Copy link to clipboard
Copied
getField sets up a connection with a form field. You get a field variable. If you get the "value" of a field variable you read from the form field (you do that). If you set the "value" of a form field you write to the form field (you don't do that).