Select to view content in your preferred language

Attribute rule to actively transfer data from a related table to it’s parent feature class and vice versa

6225
36
Jump to solution
02-07-2022 04:35 PM
tbearb
by
New Contributor III

Using ArcGIS Enterprise 10.9.1 - Field Maps version 21.4.0. I am curious if we are able to create an attribute rule to transfer a value from a related table to the parent feature class upon record submission?

I currently have attribute rules in place that transfers a water meter’s brand, meter ID, and latest reading from the parent feature class to the related work history table when the record is created. This is successful. I would like to then use another attribute rule on the feature class to automatically update the new meter ID once the new value is typed into the related work history table.

Is this type of workflow supported - actively transferring data from the parent feature to its related table and vice versa? If so, is the attribute rule created in the same manner? Unfortunately I’m not having successful results returning values from the related table back to the parent feature class.

0 Kudos
36 Replies
ChristopherBowering
Occasional Contributor III

Thanks for sharing that!  In your example, it looks like the "globalID" field in both the feature class and related table is used as the relationship key.  In the majority of my relationship classes, I use "globalID" from the feature class and a "GUID" field from the related table.  This seems to be the most efficient way to handle one-to-many relationships without having the manual update attributes to make sure the key fields are the same.  Is it possible to use your scripting if the key fields are not the same?

I'm working with a very 'dumb' testing point feature class and table so I can get it right before applying to my real work.  If my parameters are simply:

Feature Class has Field_A
Table has Field_B
Relationship Class 'Origin Primary Key' (Feature Class) is GlobalID; 'Origin Foreign Key' (Table) is GUID

All I want is for the attribute in Field_A to populate Field_B in the related table.  How would this look in your example code?

0 Kudos
tbearb
by
New Contributor III

Sorry for the delay in getting back to you. I am actually using a GUID field type as well in my scenario on my related table. My feature class is utilizing a GlobalID field type and my table is utilizing a GUID field type (field is called 'Related_Asset') within the relationship class.

tbearb_0-1665607940470.png tbearb_1-1665607984825.png

The association between the two fields happens in these lines where I am specifying the variable globalid as $feature.Related_Asset. The 'Related_Asset' field being the GUID field from the related table. The @globalid in the filter statement is being called upon against the feature class:

var globalid = $feature.Related_Asset
var filterStatement = 'globalid = @globalid'

 

 

0 Kudos
ChristopherBowering
Occasional Contributor III

Thanks for the further explanation!  I didn't realize you had used an alias for the GUID field - I thought 'Related_Asset' was a placeholder for a value/name from my own data.  I'm still having a bit of trouble 'dumbing down' your example since I don't need the 'else/if' statements in there (I'm also very new at this in general!).  If I just want to simply bring a value over from the feature class field to the table field, what would that look like?  I'm not sure how much of your code is needed for something that basic.  Thank you!

0 Kudos
tbearb
by
New Contributor III

No worries. I'm by no means an expert, I am also learning as I go. So for something a little more basic, you could maybe use something like this. I performed a test with this code. Feature class called "Test_Feature", same 1 to many relationship, "Related_Asset" GUID field on the related table, "Site" field on the feature class passes it's values to the related table in it's "Site_WH" field. Hopefully this helps. 

//Pass Site attribute to related table
//Field: Site_WH
//Triggers: Insert, Update
//Execution: N/A
var asset = FeatureSetByName($datastore, 'xxxxxxxx.DBO.Test_Feature');
var globalid = $feature.Related_Asset
var filterStatement = 'GlobalID = @globalid'
var related_data = Filter(asset, filterStatement)
var cnt = Count(related_data);

var results = "";

if (cnt > 0) {
for (var row in related_data) {
var line = row.Site;
results +=line;
}
} else {
results = "No related record";
}
return results;

 

0 Kudos
ChristopherBowering
Occasional Contributor III

I apologize for the couple weeks' delay in responding.  I have been playing around with this today.  It is partially working.  I am able to get text to carry over when there is already a record in the related table which has a GUID value matching a GLOBALID value from the feature class.  However, when I attempt to 'add new to relationship' (new related record), I receive an error.  I have all 3 triggers set in the attribute rule.  Similarly, I get the same error when I attempt to remove a record from the relationship (although 'delete' oddly works fine).  When I use the script as a pop-up expression, it also works without issue; so, the problem lies when editing and trying to add a new record.

Error_Message.JPG

Thoughts about this?

Update: I closed out of Pro and went back in to try again.  Now I am no longer receiving the message above, rather I am receiving this message below.  "Field_B" is equivalent to the "Site_WH" from your example.  It's odd because the field that this error pertains to is the one that should be populated by the attribute rule...so it shouldn't even be able to be 'invalid'...

error message.JPG

0 Kudos
tbearb
by
New Contributor III

Are you testing with a FGDB or SDE? I'm sure you've checked already, but regarding the invalid column value error, is there any sort of mismatch in field type or field properties between Field_B and the other field it is obtaining a value from? Or, any other attribute rules applied to the field?

0 Kudos
ChristopherBowering
Occasional Contributor III

I am testing within SDE.  There are no other attribute rules in play and both fields are identical in properties (text, length 10).  I'm assuming the intended attribute rule is 'Immediate Calculation'.  As I mentioned, the code is doing what it's supposed to if the table record has a matching GUID value.  Even if I create a new record and manually paste in a corresponding GUID the Field_B will populate.  Can you confirm that it works for you upon adding a new related table record (when there isn't already a related record present for the corresponding feature)?  It's almost like it's trying to run the attribute rule prior to the record being generated instead of the other way around.

var asset = FeatureSetByName($datastore, 'OCGIS.OCGIS.DPW_TESTING');
var globalid = $feature.Related_Asset
var filterStatement = 'GlobalID = @globalid'
var related_data = Filter(asset, filterStatement)
var cnt = Count(related_data);

var results = "";

if (cnt > 0) {
for (var row in related_data) {
var line = row.Field_A;
results +=line;
}
} else {
results = "No related record";
}
return results;

 

0 Kudos