Select to view content in your preferred language

Deleting a feature using arcade - help with code

643
3
Jump to solution
10-04-2024 05:17 AM
Labels (1)
TorbjørnDalløkken2
Frequent Contributor

Hi.

I'm struggeling with an attribute rule (Calculation) in ArcGIS Pro. I have a two featureclasses in a filegeodatabase (Vegteig - polygon, Tilknytningspunkt - point). The polygonclass has an ID (Teig_ID) which is used as a foreign key in the point class. When I delete a polygon, I want the corresponding point to be deleted as well. I've created an attribute rule on the polygonclass which triggers on delete and have turned on "exclude from application evaluation".

// henter teig_id fra tilknytningspunkt som slettes
var teig_id = $feature.Teig_ID

var fs_tilknytningspunkter = FeatureSetByName($datastore, "Tilknytningspunkter", ["GlobalID", "TEIG_ID"])

var tilknytningspunkt = First(Filter(fs_tilknytningspunkter, "TEIG_ID=@teig_id"))
Console(tilknytningspunkt)
var deleteList = []

if(tilknytningspunkt == null){
    return
}
else{
    var delete = {'globalId': tilknytningspunkt.GlobalID}
    Push(deleteList, delete)
}
Console(deleteList)

return
{
    'edit': [{
        'className': 'Tilknytningspunkter',
        'deletes': deleteList
    }]
}

This code seems to be working fine, as it's verified ok and I can see that point is being selected in the output to console. The problem is that the delete it self is not executed. The polygon is deleted, but the poit still remains. 

Can anyone see what's wrong?

0 Kudos
1 Solution

Accepted Solutions
VinceE
by
Frequent Contributor

The below works for me when I recreate your situation above, assuming you only want to delete the first point found with a matching ID to the polygon, and not any subsequent ones.

Other than some line formatting, I think the only difference between mine and yours is that I am explicitly creating the var "delete" dictionary using the "Dictionary()" constructor on line 14. I have had a similar problem when loading things into these return keyword dictionaries as you are doing, no idea why, but this has fixed my issue. At this point I pretty much always try to use the explicit constructor when I am able to.

// henter teig_id fra tilknytningspunkt som slettes
var teig_id = $feature.Teig_ID

var fs_tilknytningspunkter = FeatureSetByName($datastore, "Tilknytningspunkter", ["GlobalID", "TEIG_ID"])

var tilknytningspunkt = First(Filter(fs_tilknytningspunkter, "TEIG_ID=@teig_id"))
Console(tilknytningspunkt)
var deleteList = []

if (tilknytningspunkt == null) {
    return
} else {
    // ***ONLY DIFFERENCE?***
    var delete = Dictionary('globalID', tilknytningspunkt.GlobalID)
    Push(deleteList, delete)
}
Console(deleteList)

return {
    'edit': [{
        'className': 'Tilknytningspunkter',
        'deletes': deleteList
    }]
}

 

View solution in original post

3 Replies
Ehei_Dogen
Frequent Contributor

Not as familiar with the ins and outs of Arcade, but in most languages testing for null is done with 'is', not '=='

0 Kudos
VinceE
by
Frequent Contributor

Arcade uses "==" as it is written to test for null specifically. IsEmpty() is used frequently as well, but that will also return true for empty strings.

0 Kudos
VinceE
by
Frequent Contributor

The below works for me when I recreate your situation above, assuming you only want to delete the first point found with a matching ID to the polygon, and not any subsequent ones.

Other than some line formatting, I think the only difference between mine and yours is that I am explicitly creating the var "delete" dictionary using the "Dictionary()" constructor on line 14. I have had a similar problem when loading things into these return keyword dictionaries as you are doing, no idea why, but this has fixed my issue. At this point I pretty much always try to use the explicit constructor when I am able to.

// henter teig_id fra tilknytningspunkt som slettes
var teig_id = $feature.Teig_ID

var fs_tilknytningspunkter = FeatureSetByName($datastore, "Tilknytningspunkter", ["GlobalID", "TEIG_ID"])

var tilknytningspunkt = First(Filter(fs_tilknytningspunkter, "TEIG_ID=@teig_id"))
Console(tilknytningspunkt)
var deleteList = []

if (tilknytningspunkt == null) {
    return
} else {
    // ***ONLY DIFFERENCE?***
    var delete = Dictionary('globalID', tilknytningspunkt.GlobalID)
    Push(deleteList, delete)
}
Console(deleteList)

return {
    'edit': [{
        'className': 'Tilknytningspunkter',
        'deletes': deleteList
    }]
}