How to Delete Records in Related Table

222
2
Jump to solution
02-04-2022 06:14 AM
Billy
by
Occasional Contributor

Hi,

This is my system configuration:

- Arcgis Enterprise 10.8.1

- Arcgis Pro 2.9.1

- Utility Network version 4

I'm trying to delete multiple records from a related table using Arcade. My plan is to return a dictionary using the keyword "deletes". This keyword accepts 2 parameters: objectID / globalID. My question is: how could I use this keyword to delete multiple records without creating one "deletes" section in the dictionary for every record? Can I pass to "globalID" an array of globalIDs of the feature I want to delete from the related table?

Also, my parent feature have several records in the related table but I only need to delete some of those records, which I can filter using a field in the related table. If I use the function "FeatureSetByRelationshipName" I can get all the records associated with the parent feature as a FeatureSet, then filter the returned FeatureSet to leave only the features that I want to delete. The question then is how to pass all the filtered records to the return dictionary without doing it one at a time?

Regards.

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

The keywords "adds", "updates", and "deletes" require an array of dictionaries.

The exact requirements for each keyword can be found here:
Attribute rule dictionary keywords—ArcGIS Pro | Documentation

 

"deletes" just requires the globalID/objectID identifying the records that should be deleted:

 

return {
  "result": result,
  "edit": [
    {
      "className": "OtherTable",
      "deletes": [
        {"globalID": GlobalID1},
        {"globalID": GlobalID2},
        {"globalID": GlobalID3},
      ]
    }
  ]
}

 

 

You already know how to load and filter the related features, so you just have to put it all together:

 

// load related features
var related_features = FeatureSetByRelationshipName($feature, "RelationshipName")

// filter related features
var filtered_related_features = Filter(related_features, "Attribute = Value")

// create and fill the deletes array
var deletes = []
for(var f in filtered_related_features) {
  Push(deletes, {"globalID": f.GlobalID})
}

// return
return {
  "edit": [
    {
      "className": "RelatedFeatureClass",
      "deletes": deletes
    }
  ]
}

 

 


Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Regular Contributor

The keywords "adds", "updates", and "deletes" require an array of dictionaries.

The exact requirements for each keyword can be found here:
Attribute rule dictionary keywords—ArcGIS Pro | Documentation

 

"deletes" just requires the globalID/objectID identifying the records that should be deleted:

 

return {
  "result": result,
  "edit": [
    {
      "className": "OtherTable",
      "deletes": [
        {"globalID": GlobalID1},
        {"globalID": GlobalID2},
        {"globalID": GlobalID3},
      ]
    }
  ]
}

 

 

You already know how to load and filter the related features, so you just have to put it all together:

 

// load related features
var related_features = FeatureSetByRelationshipName($feature, "RelationshipName")

// filter related features
var filtered_related_features = Filter(related_features, "Attribute = Value")

// create and fill the deletes array
var deletes = []
for(var f in filtered_related_features) {
  Push(deletes, {"globalID": f.GlobalID})
}

// return
return {
  "edit": [
    {
      "className": "RelatedFeatureClass",
      "deletes": deletes
    }
  ]
}

 

 


Have a great day!
Johannes
0 Kudos
Billy
by
Occasional Contributor

Hi Johannes,

Thanks for the reply. You are right about the array of dictionaries, I didn't think about looping the feature set of related records to create the dictionary.

Regards.

0 Kudos