I'm very new to Arcade and I'm struggling with this expression in a Field Maps smart form. None of these feature layers are hosted. I want to be able to pass information back and forth between our water meter feature class and their related maintenance tables. In this expression I'm trying to read the New meter ID from the most recent maintenance table record, and use that value to overwrite the existing (old) meter ID in the feature class attributes.
//get related inspections
var maintrecords = FeatureSetByRelationshipName($feature, "W_SensusMeter_Maint_2023");
//order by date descending
var lastRec = First(OrderBy(maintrecords,"InspectionDate DES"))
var cnt = Count(maintrecords);
//the new meter id from maintenance records
var mxNewID = lastRec['MX_New_Meter_ID']
//the old id from the previous meter
var oldID = $feature.meter_id
//replace old id in main feature with new id value from latest maintenance rec
var IDSwap = Replace($feature.meter_id,oldID, mxNewID)
if (cnt >1) {
return IDSwap
}
This expression works in the console, but when it doesn't work in Field Maps or Map Viewer. I used a similar expression to pass information from the main feature into the maintenance table and it works correctly. Can someone tell me what I'm doing wrong?