I need related tables to autopopulate a new record when the parent table gets a new record

1250
7
07-18-2021 06:03 AM
Allison_Hockey
New Contributor III

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 :)

7 Replies
JohannesLindner
MVP Regular Contributor

Attribute Rules can do that.

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-attribute-ru...

 

// 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
  ]
}

Have a great day!
Johannes
0 Kudos
Allison_Hockey
New Contributor III

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?

0 Kudos
JohannesLindner
MVP Regular Contributor

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.


Have a great day!
Johannes
0 Kudos
RayGarrett
New Contributor

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.

0 Kudos
JohannesLindner
MVP Regular Contributor

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:

  • Make sure your key field is a "normal" type. I couldn't find what field types are supported by Arcade, but Integer and Text fields are for sure.
  • Make sure your primary key field is editable. The rule won't work on non-editable fields like ObjectID or GlobalID.
  • Add new key fields and try the rule on those.
  • Run this modified rule on a field in your feature class that is editable and not the primary key:

 

// 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}}
        ]
      }
  ]
}

 

 


Have a great day!
Johannes
0 Kudos
Scott_Harris
Esri Regular Contributor

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...

0 Kudos
Allison_Hockey
New Contributor III

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!

0 Kudos