Select to view content in your preferred language

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

3500
13
11-22-2022 12:10 PM
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
DominicRoberge2
Occasional Contributor III

I am not sure... I don't see a link to "share" that bug and when I search for that specific BUG on ESRI Support site, I get nothing....

Sorry. Perhaps you will have to open a ticket with support, mention this BUG number and that will help promote the issue? 🤞

0 Kudos
BRENNEJM
New Contributor III

Any update on this bug? It's a bit concerning that Esri hasn't officially published this bug (or I just haven't been able to find it anywhere) and that they don't seem to be prioritizing this. I've tried the $editContext.editType version that someone else posted in this thread and that doesn't work either. This is even more concerning to me as it means that Arcade appears to have a programmatic issue, and makes me question if other scripts are working correctly. 

0 Kudos
DominicRoberge2
Occasional Contributor III

I believe this issue has been resolved with the latest update (https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/go-beyond-the-smart-editor-using-sma...)

 

below is my revised code and not it's working as expected

 

// 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, 'FUID DESC'));
  // If the last value was empty write 1, otherwise add 1 to the value

  // calculate and return the next fuid
  var max_fuid = last_feature.FUID
  var next_fuid_number = Number(Replace(max_fuid, "EOC", "")) + 1
  return "EOC" + Text(next_fuid_number, "00000")

} else {
  // When the feature is updated, return the existing value in this field
  // and do not calculate a new value
  $feature.FUID
}

 

0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

I tried to set that code and edit but it won't let me create a new feature still either. 

0 Kudos