I am attempting to calculate a unique ID in a form for newly-added features. The unique ID should conform to the pattern YYYYddddd where YYYY is the current year and ddddd is a five-digit integer sequence denoting the order in which each feature was added (e.g., 202400001). When editing an existing feature, I'd simply like the calculation to return the existing value.
My calculated expression currently looks like this:
if ($editcontext.editType == 'UPDATE') {
if (!IsEmpty($feature["treeID"])) {
return $feature["treeID"]
}
else if ($editcontext.editType == "INSERT") {
return Number(Concatenate(Year(Today()),Text(Count(Filter($featureset,left($feature["treeID"],4)+'='+Year(Today()))) + 1,'00000')))
}
}
The Arcade code works during testing in the editor, but I receive an error (attribute failed) when attempting to add a new feature and automatically calculate the field using the form.
I would appreciate any help or advice to solve the issue!