Need help with javascript function

215
1
04-01-2020 11:46 AM
JessikaMcFarland
New Contributor

I am creating a form to assess tree measurements in the field. I have a JS function already in place that calculates the root of mean squares on the top 8 largest trees, sorted by their DBH. However, I need it to only run these calculations on two specific species of trees, and I'm not versed enough in Javascript to do so. I tried to use the relevant column but I realized this just hides the calculations on certain trees while still running the script. 

The two species abbreviations (name: tree_species) are 'PISI' and 'TSHE'. All other species cannot be included in the calculations, otherwise it will skew results. 

I have attached a script that a previous user on here helped me figure out, as well as the XLS form. If someone could give me some guidance, it would be very appreciated. I can't help but think it's an easy fix, but I have no experience with Javascript  

Thanks,

Jess

0 Kudos
1 Reply
JamesTedrick
Esri Esteemed Contributor

Hi Jessika,

Relevant calculations should prevent the calculation from working when the question is not relevant; the problem is that you function is analyzing the entire repeat data (you would need to make the values used in the calculation relevant or not relevant in the repeat).  This would be the most efficient for the javascript function as it currently exists, though you would likely want to prepend a filter to remove empty values before the sort (see Remove empty elements from an array in Javascript - Stack Overflow ).

Alternatively, you could also pass the species values and construct the array used for calculations inside the javascript function, using an if (species == 'PISI' || species == 'TSHE') to add values only when the appropriate species is listed.

0 Kudos