Select to view content in your preferred language

Unexpected Null error only when trying to save rule

1855
10
Jump to solution
07-18-2023 11:54 AM
CraigCarsley
Frequent Contributor

I spoke with @HusseinNasser2 at the conference about an issue with my Arcade expression. Using his sample, I'm trying to recreate my rule, starting with a simple intersect. Ultimately, this rule will include intersections with multiple layers, so I'm modifying the sample to use a results dictionary. 

I'm running into a problem when I try to save the attribute rule. It validates fine when I'm in the Expression editor, and console messages show a valid result. However, when I click 'Save', I'm presented with the following error: 

ERROR 002717: Invalid Arcade expression, Arcade error: Unexpected null, Script line: 8

var fs = FeatureSetByName($datastore,"City_Limits",["TOWN"],false);
var intFs = Intersects(fs, Geometry($feature));
var cityLimit = First(intFs)

return {
   'result':{
      'attributes':{
         'MUNICIPALITY':cityLimit.TOWN
      }
   }
}

 

As I said, the Expression validates normally in the Editor:

CraigCarsley_0-1689706188920.png

and the console message >> console(cityLimit.TOWN) yields:

CraigCarsley_1-1689706244453.png

If I print the entire results dictionary to the console, I get this:

{"result":{"attributes":{"MUNICIPALITY":"Omaha"}}}

 

Any ideas why I'm having a problem here?

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

Correct, if you were using the geometry on the citylimit feature then you would want to return geometry. 

 

I think you need to guard against null. As  First() might not return any result. 

var fs = FeatureSetByName($datastore,"City_Limits",["TOWN"],false);
var intFs = Intersects(fs, Geometry($feature));
var cityLimit = First(intFs)

//if the cityLimit feature is null do an early exit. 
if (cityLimit == null)  return;

return {
   'result':{
      'attributes':{
         'MUNICIPALITY':cityLimit.TOWN
      }
   }
}

 

View solution in original post

10 Replies
MikeMillerGIS
Esri Frequent Contributor
Definitely need to pass true into FSByName for the geometry parameter so intersect works.

Also, there is a chance that you intersect nothing, so you need to check if the result of first is null and exit differently.
0 Kudos
CraigCarsley
Frequent Contributor

Thanks for the swift reply, Mike.

I thought the same thing about passing 'true' into FSByName, but Hussein said it's not needed because I'm not actually doing anything with the geometry. However, I did try doing that just to see if it made a difference. It will return a geometry value, but it doesn't resolve the issue. 

I tried a few different ways to check if the result is null, but I ultimately realized the resulting feature set is not the issue. The issue occurs only when I try to access the field name TOWN in the result. If I set the result to be 'MUNICIPALITY': cityLimits (removing .TOWN), the expression still validates and I am actually able to save the rule. It's only a problem when trying to access the TOWN attribute in the City Limits fc.

Just to be on the safe side, I created a brand new feature class in a file geodatabase and copied the features manually into it so there wouldn't be any chance of overhead or corruption. The layer has a total of 8 features, none of which have a null TOWN value:

CraigCarsley_0-1689713495760.png

 

 

HusseinNasser2
Esri Contributor

Correct, if you were using the geometry on the citylimit feature then you would want to return geometry. 

 

I think you need to guard against null. As  First() might not return any result. 

var fs = FeatureSetByName($datastore,"City_Limits",["TOWN"],false);
var intFs = Intersects(fs, Geometry($feature));
var cityLimit = First(intFs)

//if the cityLimit feature is null do an early exit. 
if (cityLimit == null)  return;

return {
   'result':{
      'attributes':{
         'MUNICIPALITY':cityLimit.TOWN
      }
   }
}

 

CraigCarsley
Frequent Contributor

Thanks Nasser. I guarded against null, and I was able to save. I'm not getting any result from the attribute rule though. When I add a point, the MUNICIPALITY value remains null. It's as if the action of creating a point is getting a null cityLimit and then returning empty.

Here's my rule as it stands now:

var fs = FeatureSetByName($datastore,"City_Limits",["TOWN"],false);
var intFs = Intersects(fs, Geometry($feature));
var cityLimit = First(intFs)
if (cityLimit == null) return;

return {
   'result':{
      'attributes':{
         'MUNICIPALITY':cityLimit.TOWN
      }
   }
}

CraigCarsley_0-1689717712024.png

CraigCarsley_1-1689717788120.png

 

0 Kudos
katherinealexander_USGS
Emerging Contributor

Hello Nasser, 

I am trying to fix an attribute rule I had working in arcpro 3.0 that is now not working in 3.1.1

The rule is essentially the same as Craigs, where I have a point feature class and a poly feature class and I want to return attributes from the poly feature class to the point feature class when a point is created within a poly. 

///load the Areas poylgon class
var PhysProv = FeatureSetByName($datastore, "intermtnwest.sde.Provinces_Surficial", ["provprefix"], true)


//intersect the areas with the inserted/edited feature
var inter = Intersects(PhysProv, Geometry($feature));
var interfirst = First(inter)

// if feature is not in any area, early exit
if(interfirst == null) return;

return {
   'result':{
      'attributes':{
         'provprefix':interfirst.provprefix
      }
   }
}

 The problem that I am having is that in some areas of the polygons when I create points the return value from my rule is null when it should return a value. There are several polygons that do this and the pattern seems random. I have deleted the polys and re-created them with the same result.

katherinealexander_USGS_0-1694050361598.png

Here is one example where the point near the bottom of the poly calculated correctly and the point at the top comes out as null. 

 

Any suggestions would be very greatly appreciated. 

Thanks

0 Kudos
HusseinNasser2
Esri Contributor

hey Katherine

i see this is a direct connect sde connection, 

can you try on a filegdb and see if you see the same behavior?

and also is it possible to send a data (with just one "bad" polygon) that reproduces feel free to take any fields/ data that is not relevant.

your code looks correct so my guess it might be the spatial reference .. 

0 Kudos
katherinealexander_USGS
Emerging Contributor

Hi again, 

I exported one of my problem polygons to a filegdb like you suggested and I am not getting the error that I do when I'm in the enterprise environment. 

I attached a zip folder that contains the filegdb with all the elements to make the attribute rules work. 

Thanks so much for any insight you might have.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Can you post your sample GDB for us to test out?

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Also, on your screen shot, the rules is disabled, make sure to enable it