Hello, I'm looking for a way to get my related tables to update new records every time a new record is created in their parent table. I have one feature class with several related tables, and to have to go in an create a new record in the each of these related tables is time consuming and seems rather inefficient. Is there a quicker way to do that? Appreciate any assistance, thank you 🙂
Attribute Rules can do that.
// Calculation Attribute Rule
// Feature class, field FeatureKey (the field that relates the tables to the fc)
// Triggers: Insert
// Get the new feature's key value
var key = $feature.FeatureKey
// If key is null, return early, don't create entries in the related tables
if(IsEmpty(key) || key == null) { return key }
// create an array of the related tables
var edits = []
// fill it
Push(edits, {"className": "Table1", "adds": [{"attributes": {"FeatureKey": key}}]})
// repeat for each related table
// return the key field and edit the related tables
return {
"result": key,
"edit": edits
}
// you could also write out the complete return block
return {
"result": key,
"edit": [
{
"className": "Table1",
"adds": [
{"attributes": {"FeatureKey": key, "AnotherAttribute": null}}
]
},
{
"className": "Table2",
"adds": [
{"attributes": {"FeatureKey": key}}
]
}
// etc
]
}
Hi Johannes,
I appreciate your assistance with this. I’m going to try both methods when I get to this point in my developments amd I’ll report back here with what works best with my workflow. By chance do you know if this will work once I publish my db to arcgis online?
I know it works when publishing to the Portal. But I don't work with AGO, so I don't know if will work there.
Hi Johannes,
This is exactly the type of thing I need but unfortunately, I have not been able to get it to work yet. In ArcGIS Pro 2.8.2, with an on prem Portal at 10.9, and MS SQL Server 2019, I have a point feature class related to a table called Elec_FIXTURE with a primary and foreign key named Pole. I have added the following code as a calculation attribute rule.
// Calculation Attribute Rule
// Feature class, field FeatureKey (the field that relates the tables to the fc)
// Triggers: Insert
// Get the new feature's key value
var key = $feature.Pole
// If key is null, return early, don't create entries in the related tables
if(IsEmpty(key) || key == null) { return key }
return {
"result": key,
"edit": [
{
"className": "pTest6.GISPORTALADMIN.Elec_FIXTURE",
"adds": [
{"attributes": {"Pole": key}}
]
}
]
}
When I attempt to add a point I receive the following error:
Failed to create new feature(s).
The field type is not supported by arcade script. [
Rule name: AddFixtures,
Triggering event: Insert
Class name: pTest6.GISPORTALADMIN.LightPoles,
GlobalID: {<globalID>}
Error Number: 3
Error message: Something is wrong.]
I use a template to fill out Pole before the point is placed so the value of Pole is not null. Any insight or assistance you could offer would be appreciated.
Thank you in advance.
Hmmm, sounds like Arcade doesn't like your field type...
I'm out of my depth here, but there are a few things I'd try:
// Calculation Attribute Rule
// Feature class, field NotPrimaryKey
// Triggers: Insert
// Get the new feature's key value
var return_value = $feature.NotPrimaryKey
var key = $feature.Pole
// If key is null, return early, don't create entries in the related tables
if(IsEmpty(key) || key == null) { return return_value }
return {
"result": return_value,
"edit": [
{
"className": "pTest6.GISPORTALADMIN.Elec_FIXTURE",
"adds": [
{"attributes": {"Pole": key}}
]
}
]
}
This is possible by adding table templates to the feature template of the origin feature class.
see this help article: https://pro.arcgis.com/en/pro-app/latest/help/editing/introduction-to-feature-templates.htm#ESRI_SEC...
Thank you Scott for your assistance with this. I am planning to implement this sometime this week and will repost back here with my findings. Thanks again!
I have been trying using Attribute Rule to edit a parent feature's attribute when a child feature is updated, following the example in Attribute rule script expression examples—ArcGIS Pro | Documentation and arcade-expressions/UpdateParentFeature.md at master · Esri/arcade-expressions (github.com), but I gave it up. The error handling is poor and seems even ESRI doesn't have a clear idea of how this error happend (LMAO) 160911: The field type is not supported by Arcade script.—ArcGIS Pro | Documentation