Select to view content in your preferred language

Attribute rule not working in 3.1

1798
9
02-25-2023 06:25 AM
SarahIerley1
New Contributor II

This attribute rule works in ArcGIS Pro 3.0 but when I upgraded to 3.1 yesterday it stopped working.  Can anyone tell me why?  What changed from 3.0 to 3.1? I'm not very knowledgeable with Arcade!  I am not able to edit the layer at all with this attribute rule turned on.   Other attribute rules still work.  Here is the error message and the code:

SarahIerley1_0-1677334472789.png

// This rule will calculate the left and right municipality for a road.
// It determines if the road is completely within a intersectingArea or falls on the edge of a intersectingArea and updates the appropriate values on the road
// Define the Road Centerline fields
var jurisleft_field = "L_JURISDIC";
var jurisright_field = "R_JURISDIC";
// Define the Geopolitical Areas fields
var jurisname_field = "JURISD";
// Get the intersecting Geopolictical Areas
var intersectingAreas = Intersects(FeatureSetByName($datastore, "PublicSafetyGIS_Data.PUBLICSAFETYGIS.Test_Jurisdictions", [jurisname_field], true), $feature)
// This function will convert a polygon geometry to a polyline
function polygonToPolyline(p) {
var json = Dictionary(Text(p));
var polylineJSON = {
"paths": json["rings"],
"spatialReference": json["spatialReference"]
};
return Polyline(polylineJSON)
}
// Test if the road falls completely within a area and does not overlap any of the area's outline
// If it does update the left and right value to be equal to the area's value
var isWithin = false;
var partialOverlap = [];
for (var intersectingArea in intersectingAreas) {
if (Within($feature, intersectingArea)) {
var line = polygonToPolyline(Geometry(intersectingArea));
if (!Overlaps($feature, line)) {
var jurisleft = intersectingArea[jurisname_field];
var jurisright = intersectingArea[jurisname_field];
isWithin = true;
break;
}
// Store any boundaries the line is partially within (overlaps some of the polygons intersectingArea)
else {
Push(partialOverlap, intersectingArea);
}
}
}
// If the road does not fall within a area, attempt to find any areas that it overlaps the outline
// Then test if the polygon is on the right or left side of the line and update the right or left value
if (!isWithin) {
var isRightValue = false;
var isLeftValue = false;
for (var intersectingArea in intersectingAreas) {
var line = polygonToPolyline(Geometry(intersectingArea));
if (Within($feature, line)) {
// Offset the geometry to the right and test if it intersects the intersectingArea
var offset_geometry = Offset($feature, 5);
if (Intersects(offset_geometry, intersectingArea)) {
var jurisright = intersectingArea[jurisname_field];
isRightValue = true;
}
// Offset the geometry to the left and test if it intersects the intersectingArea
offset_geometry = Offset($feature, -5);
if (Intersects(offset_geometry, intersectingArea)) {
var jurisleft = intersectingArea[jurisname_field];
isLeftValue = true;
}
}
}
}
// If either the left or right value is not set we will loop through the partially within
if (isLeftValue || isRightValue) {
for (var i in partialOverlap) {
var intersectingArea = partialOverlap[i];
var line = polygonToPolyline(Geometry(intersectingArea));
// Get the portion of the road that overlaps the polygon intersectingArea
var intersection_geometry = Intersection($feature, line);
// Offset this portion of the road to the right and test if it intersects the intersectingArea
var offset_geometry = Offset(intersection_geometry, 5);
if (Intersects(offset_geometry, intersectingArea) && !isRightValue) {
var jurisright = intersectingArea[jurisname_field];
}
// Offset this portion of the road to the left and test if it intersects the intersectingArea
offset_geometry = Offset(intersection_geometry, -5);
if (Intersects(offset_geometry, intersectingArea) && !isLeftValue) {
var jurisleft = intersectingArea[jurisname_field];
}
}
}
return {
"result": {
"attributes":
Dictionary(
jurisleft_field, jurisleft,
jurisright_field, jurisright
)
}
}

 

 

 

9 Replies
KoryKramer
Esri Community Moderator

Maybe try re-posting in Attribute Rule questions as well https://community.esri.com/t5/attribute-rules-questions/bd-p/attribute-rules-questions 

0 Kudos
James_Whitacre_PGC
New Contributor III

I just encountered a similar issue. The Arcade syntax was correct and now it was throwing an error. Esri needs to check their syntax-checking software as I believe there is an issue with the update.

KoryKramer
Esri Community Moderator

Hi @SarahIerley1 Here is some info that I got from @HusseinNasser2 

var isRightValue = false;
   var isLeftValue = false;
must be moved outside the if  

It could be a bug in the script we were not reporting correctly before and now we are. 

Could you modify the script?

0 Kudos
JamesBurton1
Occasional Contributor

So are you saying that the acceptable syntax for Arcade has changed? All my attribute rules for ADMS have broken at Pro 3.1.1

0 Kudos
James_Whitacre_PGC
New Contributor III

@JamesBurton1 I was NOT making the claim that the Arcade syntax changed, but rather that the software that checks if the syntax is correct changed (i.e. the linter software). I suppose It is possible that the syntax changed, but in my case, I could not identify anything in the documentation that indicated the syntax changed for the Arcade code we were using. It would be great to get an Esri staff person to comment on this issue. Thanks.

0 Kudos
HusseinNasser2
Esri Contributor

Hello,

let me add context to why you are getting this object not found error at least in this particular case. Simplifying the script you have to the following

there is a condition that when met, you define a variable inside the if block and set it to a value. 

Later outside the scope of the if block you do another if and use that variable. This is variable scoping, the variable isLeft will only be defined if the first condition is met

HusseinNasser2_0-1683222306228.png

 

Now if the first condition was not met, the variable isLeft will never be defined and the second if will fail with isLeft object is error. This is because Arcade has inherited its behavior from Javascript. 

 

HusseinNasser2_1-1683222568886.png

 

 

Why did this work in 3.0 and not in 3.1? Well I could argue that the script may also fail in 3.0 or any release as well if $feature happened to not satisfy the first condition which leads to the variables to not getting defined. I think you can reproduce this in 3.0 by creating a feature outside Test_Jurisdictions. 

So the real solution for more predictable script is to define the scripts outside the scope. that is move isLeft and IsRight so they are at global scope if you are planning to use them across the script. 

 

 

If there are any other cases where the script fail but the syntax looks correct please post it in the this thread and we will take a look. 


Hope that clarifies it. Thank you and apologies for the late reply.  

JamesBurton1
Occasional Contributor

I'm having trouble with this attribute rule that used to work just fine. It seems the syntax to call a field from a variable is not working anymore. E.g. layer['zipcode']

Error is attached. Here is the rule:

var zip = FeatureSetByName($datastore, 'ZipCodes', ['ZIP5'], true);
var intersectLayer = Intersects(zip, Geometry($feature));
if (Count(intersectLayer) > 0) {
var layer = First(intersectLayer);
return layer['zipcode'];
} else {
return null;
}

0 Kudos
HusseinNasser2
Esri Contributor

Hey  James

 

FeatureSetByName you are only asking for the ZIP5 to be returned, but then you are attempting to access. the zipcode field.

 

To fix this add the zipcode field.

See if that helps. That is something we fixed in 3.1 where in some cases prior releases we were fetching all fields regardless of what you asked it to, which is why you script worked before but no longer does. 

 

var zip = FeatureSetByName($datastore, 'ZipCodes', ['ZIP5', 'zipcode'], true);
var intersectLayer = Intersects(zip, Geometry($feature));
if (Count(intersectLayer) > 0) {
var layer = First(intersectLayer);
return layer['zipcode'];
} else {
return null;
}

 

Arueira
New Contributor II

Helo,

I'm also having problems with calculations of attribute rules that were working, including in published services, and stopped working.
In my case, no error message appears, it is simply as if the rule was not fired!
This happens when I make edits, when creating new features the rules are being applied.

-----------------------------------------------------------------------------------------------

var pol_bairro = FeatureSetByName($datastore, "gisdb.cadtec.Bairros")
var i_pol_bairro = First(Intersects(pol_bairro, Centroid($feature)))
if(i_pol_bairro == null) {return null}
return i_pol_bairro.Bairro

-----------------------------------------------------------------------------------------

Does anyone have any idea why this behavior occurs, or how I can track whether the function is working?

thanks!

0 Kudos