I created a feature layer (hosted) where I am attempting to generate a unique ID each time a new feature is inserted. I have some existing data but the collectors will need to add features into the layer. I have global IDs and GUIDs in the related table, but I would like an easy to reference unique ID in my feature layer as well.
I learned how to do this in ArcGIS Pro and it was pretty straight forward. In Pro you have the option to select the trigger that initiates the attribute rule (Insert, Update, Delete). But after establishing this in Pro, I uploaded to AGOL and these settings did not carry over. So I kept Googling and I found this ESRI article on how to accomplish unique ID generation in my Field Maps form using an arcade expression.
However, after applying the arcade expression on my unique ID field, I did testing in my web map and the existing IDs change when updating features. Is there something I could add to the arcade expression so the web map knows to only generate the next sequential number when a NEW feature is added? Similar to checking the "Insert" box when establishing an attribute rule in ArcGIS Pro?
Solved! Go to Solution.
Typically I see people using the Arcade IIf(IsEmpty($feature.observation_number) for example to only calc if empty.
But as others posted this all falls apart offline. Also if you have multiple users creating features at the same time (a user adds a feature then spends say 10 minutes filling it out then user 2 starts a add during that time). Coming up with your own id field or using a GUID (or even calc the globalid into a static field) is usually a better way to go.
In order to calc at insert into the database only a backend server can do that using attribute rules - but this is not available in AGOL yet (I heard it was coming but have not seen anything lately).
As others posted we never do more than one visit to a site in a day so we use a date stamp like this. You could add time to this as well.
Concatenate($feature.PointID, "_", text(ToLocal($feature.FieldEvalDate), "Y-MM-DD"))
Hope that helps
@LyleChurch
This might be stating the obvious, but you can run into strife if multiple people are using the same dataset in Field Maps (or even Pro) while offline.
Different instances have no way of knowing what is happening in another instance while offline.
A workaround is to use something local as part of the ID such as user name, device name, etc.
If people are working in different locations you can create an underlying grid and bring that into the expression with a spatial join.
No, I appreciate you mentioning this as something to keep in mind. For this use case, the map/dataset aren't being used offline but this could come into play with other collecting maps I set up
Typically I see people using the Arcade IIf(IsEmpty($feature.observation_number) for example to only calc if empty.
But as others posted this all falls apart offline. Also if you have multiple users creating features at the same time (a user adds a feature then spends say 10 minutes filling it out then user 2 starts a add during that time). Coming up with your own id field or using a GUID (or even calc the globalid into a static field) is usually a better way to go.
In order to calc at insert into the database only a backend server can do that using attribute rules - but this is not available in AGOL yet (I heard it was coming but have not seen anything lately).
As others posted we never do more than one visit to a site in a day so we use a date stamp like this. You could add time to this as well.
Concatenate($feature.PointID, "_", text(ToLocal($feature.FieldEvalDate), "Y-MM-DD"))
Hope that helps
Thank you, Doug for all the information and a couple of examples/ideas. I am not working offline with this particular map so I may try the IIf(IsEmpty() route.
Best
Couldn't you just use:
$editcontext.editType == 'INSERT'
similar to the checkbox in Pro?
See this link for more info and example.
R_
I cannot remember but I think $editcontext.editType was different if they copied an existing point and that messed some stuff up. I would check that.