I’m looking to correlate two fields of my form, using the same index number.
I mean, I have a group of fields called traj in an array. Each traj field is (or should be) related to a niv field, with the same index number (hierarchical index), and I would like to find a specific word in one of the traj fields, get the number on the related niv field and modify the result field with it. If there isn’t the word, nothing happens.
My code is:
// there are 6 traj fields (traj.0, and so on, up to traj.5) and 6 niv fields (same way, niv.0 to niv.5), and a result field
var oAtzar = this.getField("traj").getArray(); //create the array
for (i = 0; i < oAtzar.length; i++) { //begin the loop
var tNom = oAtzar[i].valueAsString //define I'm looking for a word inside the array
if (tNom === "Jesuïta") { //if the word is the one I'm looking for...
var tNiv = this.getField("niv."+i) //check the niv field related to the traj field; same *i* value
event.value = 16 - 1*(tNiv.value) //modify the result field (autocalculated)
} else {
event.value = 16 //no word, nothing happens
}
}
However, I found some issues:
- It doesn’t modify the result field. I though as the i value is the same, it would work, but is doesn’t.
- Checking before publishing I found that it finds the word, but only in the first field. If I write it in any other field of the array, it doesn’t find anything.
I konw I can do it with a cascade of if…else, but I though it would be faster (and easier) with an array and a loop.
I hope I have detailed well enought!
Thank you in advance for your help!