Arcade Generate new Unique ID for new record but not updating existing UID

2815
13
11-22-2022 12:10 PM
Labels (1)
DominicRoberge2
Occasional Contributor III

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
}
13 Replies
JohannesLindner
MVP Frequent Contributor

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")

 


Have a great day!
Johannes
0 Kudos
DominicRoberge2
Occasional Contributor III

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!

 

 

DominicRoberge2_0-1669216898189.png

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

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.

JohannesLindner_1-1669276083269.png

 

After I clicked on "Hinzufügen" ("Add"): Now the rule did trigger, and the FUID is calculated.

JohannesLindner_2-1669276156299.png

 


Have a great day!
Johannes
0 Kudos
DominicRoberge2
Occasional Contributor III

Thanks for the info. However when the expressio is enabled, I can't click the Create Feature button.

DominicRoberge2_0-1669298218027.png

when I test the expression it seems to be working

DominicRoberge2_1-1669298284815.png

if I disable the expresssion, then I can Create  feature

DominicRoberge2_2-1669298357264.png

 

What am I missing? I also tested the process on a different HFL and different web map and same result.

0 Kudos
JohannesLindner
MVP Frequent Contributor

I'm sorry to say that I have no idea what could be the case.

Maybe @HusseinNasser2 can help?


Have a great day!
Johannes
0 Kudos
DominicRoberge2
Occasional Contributor III

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!

0 Kudos
DonSjoboen
New Contributor III

@DominicRoberge2 any updates on whether the bug was fixed?  I'm having the same issue in the form in the new map viewer.

0 Kudos
DominicRoberge2
Occasional Contributor III

this is all I got

Looks like is under review

DominicRoberge2_0-1680723568515.png

 

VanessaSimps
Occasional Contributor III

We are seeing a similar issue in one of our apps/maps. is there a way to +1 to your bug?! 

 

0 Kudos