Using the map viewer in Portal 11, I have added an editable feature service and created a edit form. The form fields use Arcade expressions to calculate field values. The expression works great, adding a new, incremented ID to each additional feature created. But when existing features are edited, the expression increases the current ID to the next available ID.
I've looked into using $originalFeature.ViolationID to compare with $feature.ViolationID of the selected feature. It works in the Test mode but fails to return anything at all in production. I've even removed all the code and just put in the code here. Instead of returning 0000001, the field ends up blank.
var org_id = $originalFeature.ViolationID
var new_id = $feature.ViolationID
return "00000001"
Is there any way to get a calculated field in a Portal map viewer editing form to not overwrite existing values when updating selected features?
Working Expression that overwrites existing ViolationID
var current_year = Number(Right(Text(Year(Today())), 2))
var ids = FeatureSetByName($map, "Arcade_Test", ["ViolationID"], false)
var id_list = []
for(var id in ids){
Push(id_list, id["ViolationID"])
}
Sort(id_list)
var list_length = Count(id_list)
var highest_id = id_list[list_length - 1]
var year_check = (Left(id_list[list_length - 1], 2))
year_check = Number(year_check)
var next_id = 1
if(Number(current_year) > year_check){
return current_year + Text(next_id, '00000')
}
next_id = Number(highest_id) + 1
return next_id