Select to view content in your preferred language

attribute rule fire twice

826
3
Jump to solution
04-04-2023 02:34 AM
solidsnake
Emerging Contributor

Hi 

i have a probleme in my attribute rule that is executed twice in my feature service

the code calculate an id that increment by +1

// get the feature with the highest id 
var m = FeatureSetByName($datastore,'oncf.dgf.urb_projet', ['*']);

var s= filter(m, "code_urb like 'URB%'")
var max_feature = First(OrderBy(s, "code_urb DESC")) 
// get the number of that id 
var max_number = 0 
if(max_feature != null) { // no features in featureset? -> this block is skipped and max_number is 0
  var txt = Replace(max_feature.code_urb, "URB", "") 
  max_number = Number(txt) 
} 
// calculate and return the new id 
return "URB" + Text(max_number + 1, "00000")

 

when i create record in arcgis pro through geodatabase evrything work perfectly, for each record i create the ID increment by +1, but when i edit the data through  feature service in Arcgis Pro or with the Edit widget in web app builder its like the attribute rule is executing twice (URB00002, URB00004, URB00006....) +2 for each new record.

 

Capture 2.PNG

thanks for you help

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

I see that you already implemented the change requested by Mike but still get the same behavior as you illustrated on another post. My guess since you are using 10.7.1 it could be a bug that we fixed in the next releases. 

Try the following script as a workaround

 

// get the feature with the highest id 
var m = FeatureSetByName($datastore,'oncf.dgf.urb_projet', ['*']);
//remove $feature from the equation.
var oid = $feature.objectid
var s= filter(m, "code_urb like 'URB%' AND objectid <> " + oid)

var max_feature = First(OrderBy(s, "code_urb DESC")) 
// get the number of that id 
var max_number = 0 
if(max_feature != null) { // no features in featureset? -> this block is skipped and max_number is 0
  var txt = Replace(max_feature.code_urb, "URB", "") 
  max_number = Number(txt) 
} 
// calculate and return the new id 
return "URB" + Text(max_number + 1, "00000")

 

ound 

 

 

View solution in original post

0 Kudos
3 Replies
MikeMillerGIS
Esri Frequent Contributor

You need to check Exclude from exclude_from_client_evaluation.  If you do not check this, the client, such as ArcGIS Pro, will run the rule and when the data is sent to the database, it will run the rule again.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/add-attribute-rule.htm#GUID-...

0 Kudos
HusseinNasser2
Esri Contributor

I see that you already implemented the change requested by Mike but still get the same behavior as you illustrated on another post. My guess since you are using 10.7.1 it could be a bug that we fixed in the next releases. 

Try the following script as a workaround

 

// get the feature with the highest id 
var m = FeatureSetByName($datastore,'oncf.dgf.urb_projet', ['*']);
//remove $feature from the equation.
var oid = $feature.objectid
var s= filter(m, "code_urb like 'URB%' AND objectid <> " + oid)

var max_feature = First(OrderBy(s, "code_urb DESC")) 
// get the number of that id 
var max_number = 0 
if(max_feature != null) { // no features in featureset? -> this block is skipped and max_number is 0
  var txt = Replace(max_feature.code_urb, "URB", "") 
  max_number = Number(txt) 
} 
// calculate and return the new id 
return "URB" + Text(max_number + 1, "00000")

 

ound 

 

 

0 Kudos
solidsnake
Emerging Contributor

the modification in the arcade code you made worked perfectly.

we will update soon to Enterprise 10.9.1, i hope il will fixe the problem.

thanks you very much

0 Kudos