We have a feature layer in a web map that is basis of an editor using Experience Builder. The clients should be able to create new features as well as edit existing features in the app.
Due to some scripts being used, we need a 'UID' field of unique numeric IDs.
It will work for our purpose if we can grab the value in the Object ID field and populate the UID field with this value when a new feature is created.
So far I am not finding any Arcade snippets that may work for this. Ideally this value would be written during the feature creation in the app, but then not editable.
Ideas?
Solved! Go to Solution.
Hi @JasonFitzsimmons -
You could use the ( $editcontext.editType=="INSERT" ) to control the field being calculate during the creation of the record but this will still be problematic if you plan on using Object ID. You cannot use the ObjectID during insert because it doesn't exist.
Okay there a few other option we could explore.
1) Calculating ObjectID from the feature layer
Get the max ObjectID from the feature layer and add one to it to get the next object ID.
The edit context type will ensure it only fires when its a new record and since it is a calculated field it will not be editable in form.
if($editcontext.editType=="INSERT")
//do the following only if the edit type is insert
{
var x = FeatureSetByName($datastore, "TEST", ["OBJECTID"], false)
if (count(x) > 0)
return Max(x,"OBJECTID")+1
else
return 1
}
else
{
return $feature.UID2
}
The first record will be different for the reason that there is no OBJECTID present to calculate the
2) Use CurrentDateTime to get a unique value
If you need a unique number then you could consider creating one out of the date time.
Solution 1 relies on reading the feature layer and I think the number of records could affect performance but with this approach, it will be agnostic of the number of records while giving a unique value. (feel free to add miliseconds to the end if you wanted to be 100% sure :D)
if($editcontext.editType=="INSERT")
{
var x = now()
var y = text(x,'YMMDDhhss')
return y
}
else {
return $feature.UID3
}
3) While the above 2 may do the trick, I think the most robust solution would be using GUID function in arcade.
https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text
Hope this helps
Hi @JasonFitzsimmons -
You could use the ( $editcontext.editType=="INSERT" ) to control the field being calculate during the creation of the record but this will still be problematic if you plan on using Object ID. You cannot use the ObjectID during insert because it doesn't exist.
Okay there a few other option we could explore.
1) Calculating ObjectID from the feature layer
Get the max ObjectID from the feature layer and add one to it to get the next object ID.
The edit context type will ensure it only fires when its a new record and since it is a calculated field it will not be editable in form.
if($editcontext.editType=="INSERT")
//do the following only if the edit type is insert
{
var x = FeatureSetByName($datastore, "TEST", ["OBJECTID"], false)
if (count(x) > 0)
return Max(x,"OBJECTID")+1
else
return 1
}
else
{
return $feature.UID2
}
The first record will be different for the reason that there is no OBJECTID present to calculate the
2) Use CurrentDateTime to get a unique value
If you need a unique number then you could consider creating one out of the date time.
Solution 1 relies on reading the feature layer and I think the number of records could affect performance but with this approach, it will be agnostic of the number of records while giving a unique value. (feel free to add miliseconds to the end if you wanted to be 100% sure :D)
if($editcontext.editType=="INSERT")
{
var x = now()
var y = text(x,'YMMDDhhss')
return y
}
else {
return $feature.UID3
}
3) While the above 2 may do the trick, I think the most robust solution would be using GUID function in arcade.
https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text
Hope this helps
Thanks! we have actually been looking at both of these options.