Select to view content in your preferred language

Arcade - Push Edits to Multiple Related Records

363
1
10-25-2024 05:46 AM
Labels (3)
ZachBodenner
MVP Regular Contributor

Hello, 

I am attempting to use arcade to push edits from a parent feature class to all of its related child records. 

// get the related asset
var asset_id = $feature.CaseNumber
var assets = FeatureSetByName($datastore, "epgdb.DISPATCH.EOCSearchedAreas")
var asset = Filter(assets, "CaseNumber = @asset_id")
console (count(asset))

for (var a in asset)
{
 return {
    edit: [{
        className: "epgdb.DISPATCH.EOCSearchedAreas",
        updates: [{
            objectID: a.OBJECTID,
            attributes: {
                Active: $feature.Active,
            }
        }]
    }]
  }
}

 

Both the parent dataset and the child have  fields called CaseNumber and Active. When a new child record is created, there's an attribute rule running an intersect that populates the case number from the parent feature, which works just fine. We want to be able to ensure that all of the child areas' "Active" values reflect the same as the parent.

This code winds up pushing the edit to the first related record, but not all of them, which is what I would expect from the for loop. The count in the console does show that there are multiple features passing through the filter.

Happy mapping,
- Zach
0 Kudos
1 Reply
ZachBodenner
MVP Regular Contributor

An update: 

I think the issue was that the for loop included the return, which perhaps was ending the loop at the first filtered record? I'd love to have someone confirm if that's how that works. Here's the code that wound up doing what I needed:

// get the related asset
var asset_id = $feature.CaseNumber
var assets = FeatureSetByName($datastore, "epgdb.DISPATCH.EOCSearchedAreas")
var areas = Filter(assets, "CaseNumber = @asset_id")
console (count(areas))
var saUpdates = []

for(var a in areas) {
  var update = {
    objectID: a.OBJECTID,
    attributes:{ Active: $feature.Active }
  }
  Push(saUpdates, update)
 }

return {
    edit: [{
        className: "epgdb.DISPATCH.EOCSearchedAreas",
        updates: saUpdates        
        }]
  }

 

Even though I was using JohannesLinder's great code examples from this thread, I went a little further in terms of complexity (I've never actually used the Push function before), so thanks again Johannes for providing all of those excellent examples!

I'll admit...I'm still not 100% sure how this code works. ESRI's documentation on the Push function doesn't seem to explain it in plain enough form for me I guess. While I understand that the variable "update" is getting appended to an array (which begins as empty), I'm still a little unsure of how that works with the edit portion. If anyone wanted to weight in on how exactly that all works, I'd love to hear it!

Happy mapping,
- Zach
0 Kudos