Select to view content in your preferred language

How to return null in Arcade with Calculate Field (python works fine)?

23365
28
12-21-2018 02:26 PM
JimmyKnowles
Frequent Contributor

Trying to use the Calculate Field GP tool in ArcGIS Pro 2.2.3. I need to use logic (if else statements) to modify some field values.

I've searched and searched and can't find how to do this in Arcade.

In python, the following works fine. It actually sets the field to Null (verified by an isNull definition query).

return None‍

In Arcade, the following just returns 0

return null‍

I've tried a bunch of other things with Arcade, but no success.

Anyone have any ideas how to return null with Arcade?

28 Replies
TL2
by
Frequent Contributor

Looks like its fixed in 2.5 

TL2
by
Frequent Contributor

This is not fixed in 2.5 within Attribute Rules.

 BUG-000119064: Calculating a value to null using Arcade returns 0 is fixed when using the stand alone Calculate Field tool.

https://community.esri.com/thread/247788-cant-return-null-when-using-attribute-rule-editupdate-and-a... 

0 Kudos
BertKraan
Emerging Contributor

I came along this issue after a 'feature class to feature class' conversion altered the <null> values in one of my attributes to '0' (arcgis pro 2.6.0)

I used this calculate field expression to fix it:

iif ($feature.wijziging == 0,null,$feature.wijziging)

Not very happy about the unwanted conversion though but happy enough to find your tips here!

Have a great day Guys!

Bert

0 Kudos
LyonMNGIS
Frequent Contributor

Hi,

I am still having issues with null in Arcade for text fields.  Has anyone had any luck with null values for text fields?

iif (OutString == '', null, OutString);

 

Thanks

0 Kudos
AJR
by
Frequent Contributor

This bug also manifests itself if you try to use an arcade expression to operate on the shape and some of the shapes are null.  There doesn't seem to be any way in arcade to detect if the shape is null before attempting to use it (i.e. intersect it with another feature class).  I'm curious when/if this bug is on the timeline for getting fixed.

0 Kudos
Bud
by
Esteemed Contributor
0 Kudos
Bud
by
Esteemed Contributor

Arcade:

Instead of checking for a null shape, can you count the vertices? If there are no vertices, then could you assume the shape is null? (or the geometry is nill or null)

Or if it is a line or polygon FC, could you check if the length is greater than 0? If I remember correctly, it's possible to check the length using an Arcade function or by referring to the Shape.Length "field". Related comment here: hasCurve Arcade geometry property.

 

SQL:

Is there a way to check if the shape is null using SQL (within the Arcade expression)?

Or if not, could you use a related database view that has a calculated field for flagging isNull (0 or 1)? And then use Arcade to reference the flag field in the related view?

Related:

0 Kudos
AJR
by
Frequent Contributor

There isn't an arcade function to count the number of vertices in a shape - https://developers.arcgis.com/arcade/function-reference/geometry_functions/

using Count(Text(Geometry($feature))) returns a result when used in the field calculator (null shapes are returned as empty strings), but trying to use Count(Text(Geometry($feature))) > 0 as a null shape filter fails when used as part of an attribute rule (i.e. null shapes pass the check)

0 Kudos
Bud
by
Esteemed Contributor

For what it's worth, I was able to set a value to null using Arcade in the field calculator in ArcGIS Pro 3.2.2 (mobile and file geodatabases):

Bud_0-1707849505755.png

return null

It worked for setting the shape field to null as well (mobile and file geodatabases).

0 Kudos