@ZacharySutherby the hydrants example was pretty instructive, but I'm finding it doesn't feel like it exactly behaves as i anticipate with regard to how it purports to get and display the 'last condition' value. My expectation was that a) if there were no prior inspections it would display the "no inspections logged" text. But, once an inspection is logged, it would display the condition value from the most recent record from the repeat. However, it appears that this shows the 'current' value in the unsubmitted inspection record, rather than the last submitted one. Is there an error in the way that the java script is capturing the data from the last submitted record? This is functionality that I want to employ in my form for a couple of different reasons, so I'd like to pin this aspect down.
Here is the JS script that seems to be the engine behind this approach and I think its lines 4 and 5 that may not be behaving as i am expecting.
function getLastCondition(inspections,maxDate){
if (inspections.length>0) {
var maxDateInspections = inspections.filter(item => item.inspection_date === maxDate);
var countOfInspectionsWithMaxDate = inspections.filter(item => item.inspection_date === maxDate).length;
var conditionOfMaxDate = maxDateInspections[countOfInspectionsWithMaxDate-1].asset_condition;
return conditionOfMaxDate
}
}