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.
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
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)?
@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.
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)
@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
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.
HTH somebody else.
Tyler
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?)
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.
Ah, that might be the issue. Based on previous entries on the community, Hosted services cannot have attribute rules applied:
Though I would also suggest marking the removal of the First function as a solution since it solved the Arcade error you were getting.
@ZachBodenner , It seems you are correct that attribute rules are not supported in hosted feature classes. Interesting. Thank you.