Select to view content in your preferred language

Attribute Rule - deleting a value from an edited feature to features it intersects

1119
9
10-31-2023 03:16 PM
Boomer1187
Emerging Contributor

Hi everyone,

I've successfully created an attribute rule on a Projects B feature class that updates a project_number field in a Projects A feature class, based on any time a new polygon is created in a Projects B feature class with the project_number from the newly created Projects B polygon (i.e. PP-2024-12345).

This attribute rule ensures that this project_number is only inputted in the project_number field in the Projects A feature class only if the polygon from the newly created Projects B feature class intersects with one or multiple projects from Project A. I've tested this out and it currently works (albeit with some syntax issues like having a ';' inputted at the start of the result). I am wondering what it would look like to alter the script below for deleting purposes of projects from Projects B? 

So any time a project/polygon is deleted from the Projects B feature class, it will then delete the project_number(s) for the intersecting underlying polygons from the Projects A feature class if that makes sense. So it will know to delete the project_numbers for any previous intersecting polygons from the initial Projects A feature class anytime a separate user will delete a project/polygon from Projects B.

 

--

var ProjA = FeatureSetByName($datastore, "Projects_A", ["GlobalID"], true)
var IntProj = Intersects(ProjA, $feature)
var updates = []
var i = 0
for (var proj in IntProj){
updates[i++] = {'GlobalID': proj.GlobalID,
'attributes': {'project_number': $feature.project_number}
}
}
return {
'result': $feature.project_number,
'edit': [{
'className': 'Projects_A',
'updates': updates
}]
}

0 Kudos
9 Replies
MikeMillerGIS
Esri Frequent Contributor

When posting code, make sure add as a code snippet.  Makes it much easier to read.

If you are just trying to null out the features values, it is a simple change to your code.  You will need a seperate attribute rule or you can use the edit context 

var ProjA = FeatureSetByName($datastore, "Projects_A", ["GlobalID"], true)
var IntProj = Intersects(ProjA, $feature)
var updates = []

var proj_num = iif($editcontext.editType == "DELETE",null,$feature.project_number)
for (var proj in IntProj) {
    psuh(updates, {
        'GlobalID': proj.GlobalID,
        'attributes': {'project_number':proj_num}
    })
}
return {
    'result': $feature.project_number,
    'edit': [{
        'className': 'Projects_A',
        'updates': updates
    }]
}

 

0 Kudos
Boomer1187
Emerging Contributor

Hi @MikeMillerGIS 

Thanks so much for the snippet and or your advice on using the code snippet feature. I will definitely use that in the future.

I had tried the above with a new separate attribute rule but when deleting a feature from Projects_B, the value is still retained in the project_number of the underlying intersecting Projects_A feature class unfortunately

Boomer1187_0-1699467118875.png

 

Do you think using the replace() function would work for the underying project_number from Projects_A? Is there a function to remove a value from the string or would it be the replace() with ""?

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Without seeing the rule you used, I am not sure.  The script I posted should work.  The return edits of the delete, should update those features.

0 Kudos
Boomer1187
Emerging Contributor

Hi @MikeMillerGIS ,

Here are my current attribute rules for now 🙂

First one is an attribute rule applied on Projects_A, that updates the project_number for any intersecting polygons from Projects_B that intersect with a new or updated project from Projects_A. This is triggered on Insert and Update with the exclude from application evaluation checked on.

var projB = Intersects(FeatureSetByName($datastore, 'Projects_B', ['project_number']), $feature)

var proj_nums = []

for (var projB_row in projB) {
    Push(proj_nums, projB_row.project_number)
}
return Concatenate(proj_nums, "; ")


The second one is an attribute rule applied on Projects_B, that updates the project number field in the Projects_A feature class from any new polygons from Projects_B that intersects with the underlying Projects_A polygons. This is triggered on Insert and Update with the exclude from application evaluation checked on.

var ProjA = FeatureSetByName($datastore, "Projects_A", ["GlobalID"], true)
var IntProj = Intersects(ProjA, $feature)
var updates = []
var i = 0
for (var proj in IntProj){
  updates[i++] = {'GlobalID': proj.GlobalID,
                'attributes': {'project_number': $feature.project_number}
               }
}
return {
   'result': $feature.project_number, 
   'edit': [{
        'className': 'Projects_A',
        'updates': updates           
    }]
}

This is the attribute rule in question applied to Projects_B, where whenever a project/polygon is deleted from Projects_B, that it triggers to delete the project_number value only, from the intersecting Projects_A polygon. The Projects_A polygon's project_number may have a single project_number or multiple separated with a ; depending on how many it intersects with. It is applied on Update and Delete with the exclude from application evaluation box checked on:

var ProjA = FeatureSetByName($datastore, "Projects_A", ["GlobalID"], true)
var IntProj = Intersects(ProjA, $feature)
var updates = []

var proj_num = iif($editcontext.editType == "DELETE",null,$feature.project_number)
for (var proj in IntProj) {
    psuh(updates, {
        'GlobalID': proj.GlobalID,
        'attributes': {'project_number':proj_num}
    })
}
return {
    'result': $feature.project_number,
    'edit': [{
        'className': 'Projects_A',
        'updates': updates
    }]
}





0 Kudos
MikeMillerGIS
Esri Frequent Contributor

You will need to adjust the logic to not null out the project number and just remove it from the ; delimited list.  but I would start to ensure the logic is working.  Make a delete only rule like this and ensure it is working

 

var ProjA = FeatureSetByName($datastore, "Projects_A", ["GlobalID"], true)
var IntProj = Intersects(ProjA, $feature)
var updates = []

for (var proj in IntProj) {
    psuh(updates, {
        'GlobalID': proj.GlobalID,
        'attributes': {'project_number':null}
    })
}
return {
    'result': $feature.project_number,
    'edit': [{
        'className': 'Projects_A',
        'updates': updates
    }]
}
0 Kudos
Boomer1187
Emerging Contributor

Sounds good, I've tested the logic to see if it works with the above and upon deletion, and panning around, I still get the same result that shows in the pop up still for Projects A with the project_number still there. 

Boomer1187_0-1699549330714.png

I tried deleting via deleting the row in the attribute table for Projects B as well as deleting via the edit ribbon for Projects B.

0 Kudos
Boomer1187
Emerging Contributor

Note, I autocorrected the psuh to 'push' as well in my code

0 Kudos
Boomer1187
Emerging Contributor

https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/originalfeature-new-attribute-r...

@HusseinNasser2 I've been racking my brain and implementing so many different variations of the above to no avail. I am utilizing ArcGIS Pro 3.1 and Enterprise 10.9.1 and a FGDB to test. I noticed you wrote this useful article regarding original feature globals. Do you think this would serve my purpose in nulling or removing the project_number value in Projects_A anytime an intersecting record n Projects_B is deleted/removed? Perhaps if it is used for the global id value or any other value that would essentially 'change' if a polygon from Projects_B is deleted? Any advice would be helpful - thanks so much.

0 Kudos
SydorukMariya
Occasional Contributor

Hi @Boomer1187 , do you have any news or a functioning workaround for this issue yet?

I've been trying to do something similar, i.e. to force update on the feature in layer B which intersects or has a common attribute value with the feature in layer A that is being deleted. This update in layer B would then trigger another attribute rule set on that layer.  As far as I get it, references to either $feature or $originalfeature global variables don't work for the delete context as the feature no longer exists when the rule is evaluated.

My only idea is to force update on all features in the target layer, but well... that's obviously not effective. 

0 Kudos