Add Attribute Rule, Help With Arcade Expression (Pass value from Parent to Child, Calculation)

380
8
03-15-2024 08:45 AM
TylerT
by
Occasional Contributor III

I am adapting an arcade expression attribute rule by @JohannesLindner (https://community.esri.com/t5/arcgis-pro-questions/attribute-rule-to-pass-a-value-from-parent-to/m-p...) where I have a relationship class.  Arcade isn't a particular strength and could use an assist debugging.  Here is this script and the error. 

TylerT_0-1710517236863.png

I need to pass a field value (project_pw) from parent to child when children are created.

Any tips would be greatly appreciated.

 

Tyler

ArcGIS Pro3.2.0

<for copy/paste>

 

// by JohannesLindner, <edited>
var parent_fs = FeatureSetByRelationshipName($feature, "t12_projects_rc")
// return nothing if no parent feature was found
var parent = First(parent_fs)
if(parent == null) { return }
return parent.project_pw

 



<error>
Invalid expression.
Error on line 4.
Expected array or feature set

0 Kudos
8 Replies
ZachBodenner
MVP Regular Contributor

Have you tried removing the First function? I'm wondering if the FeatureSetByRelationshipName is already grabbing only the one parent feature, and thus first would be throwing an error because it's looking for an array (ie multiple things)?

TylerT
by
Occasional Contributor III

@ZachBodenner; That cleared the invalid expression.  I now have a valid expression.  Thank you.  Maybe the First() is for a many to many?  

New problem.  The tool runs but fails with this error.

TylerT_0-1710521213753.png

Any ideas about this error?

<snip>

ERROR 002764: ERROR: code:500, JSONObject["extent"] not found., Internal server error.
Failed to execute (AddAttributeRule).
Failed at Friday, 15 March, 2024 12:05:55 (Elapsed Time: 2.81 seconds)

 https://pro.arcgis.com/en/pro-app/3.1/tool-reference/tool-errors-and-warnings/001001-010000/tool-err...

0 Kudos
TylerT
by
Occasional Contributor III

@ZachBodenner,

 I've moved out of the hosted feature class and into two other test environments and this is what I get.

gdb:  Original code passes linter and rule is applied.  ArcGIS Pro works as expected passing value to child.

var parent_fs = FeatureSetByRelationshipName($feature, "t12_projects_rc")
var parent = First(parent_fs)
if(parent == null) { return }
return parent.project_pw


edgb: The linter rejects the code above (and OP code).  The linter only accepts this code (no First()), as you suggested.  However, once the rule is applied, the child table does not work.  No value is passed to child  in ArcGIS Pro, and errors occur published web apps.

var parent_fs = FeatureSetByRelationshipName($feature, "t12_projects_rc")
if(parent_fs == null) { return }
return parent_fs.project_pw


I tried both traditional and branch version db connections.  Any other ideas?

Tyler
Enterprise 11.2
ArcGIS Pro 3.2.0

0 Kudos
TylerT
by
Occasional Contributor III

Hi All,

Okay, A couple of days of pounding my head against the wall and I figured it out.  The FeatureSetByRelationshipName function in the Arcade Expression required the full EGDB table name (i.e. 'DBO...') as shown below, contrary to the in_table argument of the arcpy.management.AddAttributeRule() method which does not.

TylerT_0-1711025698710.png

HTH somebody else.

Tyler

0 Kudos
ZachBodenner
MVP Regular Contributor

To me this looks like it's related to the actual data you're dealing with. Can you talk a little about the databases your data is coming from? What kind of files are they (feature class and geodatabse table?) 

0 Kudos
TylerT
by
Occasional Contributor III

The Parent is a hosted Feature Service Feature Class (polygon) on ArcGIS Enterprise Portal.  The Child is a hosted Feature Service Table.  They are related by a 1:M feature class.

The field I want to pass from Parent to Child is a text field (basically project number).  Some Parent fields are null.  The desire triggers are insert and update.

0 Kudos
ZachBodenner
MVP Regular Contributor

Ah, that might be the issue. Based on previous entries on the community, Hosted services cannot have attribute rules applied:

https://community.esri.com/t5/attribute-rules-questions/can-attribute-rules-be-used-on-feature-servi....

Though I would also suggest marking the removal of the First function as a solution since it solved the Arcade error you were getting.

0 Kudos
TylerT
by
Occasional Contributor III

@ZachBodenner , It seems you are correct that attribute rules are not supported in hosted feature classes.  Interesting.  Thank you.

0 Kudos