Hi all,
I have a JavaScript script/function that identifies which record within a repeat has the most recent date and returns the 'number' of that repeat. That number is then used elsewhere to bring back another date value from that repeat record to populate a field in the survey's main table.
In the field app this all works perfectly, but when I view it in the web form version it doesn't. From what I can see it it returns the number of the repeat as '6' or '9' (depending on the date value) even when there aren't anywhere near that number of records with the repeat.
I know there are limitations with using JavaScript within the web form, so I was wondering:
1) Is this one of the limitations (and if so what actual is the nature of the limitation I'm seeing)?
2) If it isn't one of the limitations, what am I doing wrong? Is there a solution/better way to do this?
I've attached a version of my .xlsx and the script is as below. I'm logged in when I'm running this and I'm also a beginner with using JavaScript so may not be understanding things properly.
Any help anyone can offer would be hugely appreciated.
/*
* JavaScript functions for Survey123
*/
function indexMax(fieldname){
var maxValue = fieldname[0];
var maxIndex = 0;
for (var i =1; i<fieldname.length; i++){
if (fieldname[i]>maxValue){
maxIndex = i;
maxValue = fieldname[i];
}
}
return maxIndex;
}
Solved! Go to Solution.
Ah that's good to know. Many thanks for replying - and all your hard work on Survey123 - it's much appreciated.