Hello
I have the following Arcade code to create a new Unique ID on a feature layer (hosted on ArcGIS Server). It's working fine for a NEW record, but if I try to select an existing record, it will update the UID field with the next available number.
How can I avoid to overwrite an existing value? Thanks for any help you could provide.
D
var fs=FeatureSetByName($datastore,'dr_testPts',['FUID'],false);
var cCurrentFUID = $feature.FUID
var fFilter = Filter(fs, 'FUID IS NOT NULL');
var fMax = 0
var tMax = 0
for (var k in fFilter){
fMax = Max(Right(k.FUID, Count(k.FUID)-3))
tMax = When(fMax>tMax,fMax, tMax)
}
tMax +=1
var vNewFUID = "EOC" + text(tMax, "00000")
if (IsEmpty(cCurrentFUID)){
return vNewFUID
} else {
return cCurrentFUID
}
You have to check if the field is already filled at the start. If yes, just return that value.
Also, your rule can be simplified a bit:
// if this feature already has a fuid, return that
if(!IsEmpty($feature.FUID)) { return $feature.FUID }
// get the feature with the greatest fuid in the featureset
var fuid_features = Filter($featureset, "FUID IS NOT NULL")
var max_fuid_feature = First(OrderBy(fuid_features, "FUID DESC"))
// for an empty featureset, this will be null, so return the first fuid
if(max_fuid_feature == null) { return "EOC00001" }
// calculate and return the next fuid
var max_fuid = max_fuid_feature.FUID
var next_fuid_number = Number(Replace(max_fuid, "EOC", "")) + 1
return "EOC" + Text(next_fuid_number, "00000")
Hi Johannes
thanks for helping me on this. I modified my expression accordingly and when I tried it in the web map.... nothing.... Then I decided to try it in the Field Maps app and it was working just fine (new record and updating existing record). I then tried to create and Experience Builder app to see how it would behave... same as web map, Empty FUID field.
Any idea why it's not working properly in the web map? For this project, my users will enter/modify data either through a web map or experience builder app.
Thanks!
This looks as if you have not actually created the feature yet. The attribute rule doesn't trigger when you put the point in, only when you finish the feature creation.
In the feature creation window: The FUID isn't there, because the rule didn't trigger yet.
After I clicked on "Hinzufügen" ("Add"): Now the rule did trigger, and the FUID is calculated.
Thanks for the info. However when the expressio is enabled, I can't click the Create Feature button.
when I test the expression it seems to be working
if I disable the expresssion, then I can Create feature
What am I missing? I also tested the process on a different HFL and different web map and same result.
I'm sorry to say that I have no idea what could be the case.
Maybe @HusseinNasser2 can help?
hello everyone
sorry it took so long, I had open a ticket with ESRI Support regarding this issue and they finally created a BUG as they were able to replicate the issue:
Bug Number: BUG-000154427
Synopsis: The Arcade expression configured in a form within a web map does not get honored in Map Viewer
Any ideas how I could generate a unique ID automatically?
Thanks!
@DominicRoberge2 any updates on whether the bug was fixed? I'm having the same issue in the form in the new map viewer.
this is all I got
Looks like is under review
We are seeing a similar issue in one of our apps/maps. is there a way to +1 to your bug?!