Hi,
I have a dataset which is our primary use case for editing and when capturing new features I'm setting up smart forms to help the user. The main one I'm struggling with is our reference number and the ability to auto populate the next sequential number. The data field, just to confuse matters more, is a string. I'm getting better at arcade but still in my learning days so I think what I need to do is...
Our standard reference number format is "ESCO - 1234" and I'm just looking to increase the highest value by 1 each time a new record is created. The reference number is stored in the field "ESCO_Ref".
1) convert the string to an integer. The reference number will always be the last 4 characters of the string.
var ESCO_num = Number(Right('$feature.ESCO_Ref', -7));
// Define the edit context so the value is only calculated when the feature is created
if ($editContext.editType == "INSERT") {
// Lookup the value for the last created feature
var last_feature = First(OrderBy($layer, 'ESCO_Ref DESC'));
// If the last value was empty write 1, otherwise add 1 to the value
return IIf(IsEmpty(last_feature), 1, last_feature.ESCO_Ref + 1)
} else {r(Right('$feature.ESCO_Ref', -7));
// When the feature is updated, return the existing value in this field
// and do not calculate a new value
$feature.ESCO_Ref
}
3) prefix the new value with "ESCO - "
return "ESCO - " + variable above
Whilst the above may be very clunky and possibly not correct, I'm just struggling with how to put the steps into one seamless expression. Any help would be greatly received folks!
Many thanks!