Select to view content in your preferred language

Attribute Rule: What am I doing wrong?

1164
3
Jump to solution
01-16-2020 08:32 AM
ThomasColson
MVP Frequent Contributor

From arcade-expressions/CopyValueIntersectingFeature.md at master · Esri/arcade-expressions · GitHub , I have 

// This rule will populate the edited features field with a value from an intersecting feature

// Value to copy from the intersected feature
var intersecting_field = "GRTS_ID";
//Field rule is assigned to in the Attribute Rule
var feature_field = "GRTS_ID";

// Create feature set to the intersecting class using the GDB Name
var intersecting_featset = FeatureSetByName($datastore, 'NABAT_CONUS_10x10_KM_GRID_CELLS_PRJ', [intersecting_field], true);

// Intersect the edited feature with the feature set and retrieve the first feature
var intersected_feature = First(Intersects(intersecting_featset, $feature));

// Check to make sure there was an intersected feature, if not, return the original value
if (intersected_feature == null)
{
    return $feature[feature_field];
}
// If the intersected feature is null, return the original value
if (IsEmpty(intersected_feature.GRTS_ID))
{
    return $feature[feature_field];
}
// Return the intersected features value
return intersected_feature[intersecting_field];

and 

Where NABAT_CONUS_10x10_KM_GRID_CELLS_PRJ is a polygon feature class with the field GRTS_ID (Type Long) and the field I'm wanting to edit in the source feature class is also GRTS_ID (Type Long). 

What is happening though is on insert and update, the GRTS_ID field in the feature class being edit instead gets the ObjectID of the intersecting Polygon. 100% sure I've gotten something wrong here. 

1 Solution

Accepted Solutions
KellyKoenig
Regular Contributor

I created some dummy data with your layer/attribute names and created an attribute rule using the exact code you pasted. The 'GRTS_ID' attribute from the 'NABAT_CONUS_10x10_KM_GRID_CELLS_PRJ' layer was copied as expected instead of the Object ID so I don't think your code is wrong.

Maybe try deleting the rule that's giving you trouble, restarting Pro, and creating the rule again? Or you could export a copy of the two datasets and create the rule using the copied layers to see if it's a quirk with the original feature layer.

View solution in original post

3 Replies
KellyKoenig
Regular Contributor

I created some dummy data with your layer/attribute names and created an attribute rule using the exact code you pasted. The 'GRTS_ID' attribute from the 'NABAT_CONUS_10x10_KM_GRID_CELLS_PRJ' layer was copied as expected instead of the Object ID so I don't think your code is wrong.

Maybe try deleting the rule that's giving you trouble, restarting Pro, and creating the rule again? Or you could export a copy of the two datasets and create the rule using the copied layers to see if it's a quirk with the original feature layer.

ThomasColson
MVP Frequent Contributor

That was the first thing I tried...exported everything to a FGDB, same result. Both datasets have same projection. 

KellyKoenig
Regular Contributor

Hmm. Maybe create a new FGDB with two new feature layers and import the field map schema from the original feature layers. Copy a handful of records from each original feature layer and paste them into the new feature layers (or create dummy polygon features that you fill in with a random "GRTS_ID'), then create the rule again. That would be a truer "clean slate" approach than exporting copies of the feature layers themselves.