Select to view content in your preferred language

Arcade Expression works in pop-up but not as attribute rule

569
4
Jump to solution
01-16-2024 11:43 AM
Rgehman
New Contributor III

I am attempting to apply a fairly simple attribute rule to a feature class in an Enterprise geodatabase. I have a polygon layer and a point layer that participate in a relationship class. I am trying to create an attribute rule on a field in the polygon layer that makes it so when the corresponding field in the point feature class is updated, the field in the polygon layer is automatically updated with that same value.

I found a script on another Esri Community post that accomplishes this using FeatureSetByName and Filter and got the arcade script to return the result I am looking for in a pop-up, but when I use that same code in the attribute rule expression box, the rule is not enforced when data is updated. I will note that both features are in the same Geodatabase. Additionally, I created a script that accomplishes the same goal using FeatureSetByRelationshipName which also worked in pop-ups but not for an attribute rule. Below are examples of both of the scripts:

 

 

// Updating field using FeatureSetByName

var key = $feature["KeyField"]

// search for related features in point feature layer
var points= FeatureSetByName($datastore, "pointlayer", ["KeyField"], "UpdateField"], false)
var filtered_fc = Filter(points, "KeyField = ")

// if no related features found
if(Count(filtered_fc) == 0) {
  return null
}

// related feature(s) found -> return UpdateField of the first one
return First(filtered_fc)["UpdateField"]
// Updating field using FeatureSetByRelationshipName

Var relationship = FeatureSetByRelationshipName($feature, 'point_polygon_rc', ['UpdateField'], false);
if(Count(relationship) == 0) { return null }
return First(relationship)["UpdateField"]

 

 

 

1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor

I re-read your description and this will not work.  You need to assign the rule on the point layer, so that when point layer field is changed, it searches for related polygons and then issues a return edit statement to update the polygon.  Changing a value on the point will not trigger the AR on the polygon.

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-k...

View solution in original post

4 Replies
MikeMillerGIS
Esri Frequent Contributor

That code should not pass validation, try this.

 

var key_value = $feature["KeyField"]

// search for related features in point feature layer
var points= FeatureSetByName($datastore, "pointlayer", ["UpdateField"], false)
var filtered_fc = Filter(points, "KeyField = @Key_value")

var first_feat = First(filtered_fc);

// if no related features found
if(IsEmpty(first_feat)) {
  return null
}

// related feature(s) found -> return UpdateField of the first one
return first_feat["UpdateField"]

 

0 Kudos
Rgehman
New Contributor III

Ah- looks like when I was adjusting my code to remove references to my actual features I deleted (but forgot to replace) "@key" on line 7. In any event, I adjusted the code as you suggested and got the same result. The expression works to display the value in a pop-up, but did not work as an attribute rule. 

I'm confident both sections of my original code are correct (with the exception of the typo in the initial post) as they both produce the correct result in a pop-up. It seems to be an issue with Attribute Rules more generally.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

I re-read your description and this will not work.  You need to assign the rule on the point layer, so that when point layer field is changed, it searches for related polygons and then issues a return edit statement to update the polygon.  Changing a value on the point will not trigger the AR on the polygon.

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-k...

Rgehman
New Contributor III

That makes sense! Thanks for pointing that out. When I applied the rule to the point layer and adjusted the code to reference the point feature instead of the polygon, updates to the field in the polygon layer updated the field in the point layer, but only when I attempted to manually update the field in the point layer. It essentially overwrote any value I tried to input with the value in the polygon field.

I'm going to need to adjust the code since it was previously written with the previous directionality in mind. Thanks for pointing me in the right direction!

0 Kudos