Select to view content in your preferred language

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

22018
28
12-21-2018 02:26 PM
JimmyKnowles
Occasional Contributor II

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
KoryKramer
Esri Community Moderator

Hi Mark - unfortunately, no, it has not yet been addressed.  You should now be able to find it here: https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDExOTA2NA== where you can click the Subscribe button.

The implicit casting behavior of null is to go to 0 in Arcade. There are cases where we override this so the dev team will look at getting the correct overrides in place...

TanyaBagley-Online
New Contributor III

I recently needed to populate some fields with a true <Null> value instead of a 0.

In ArcGIS Pro, using Arcade to try and calculate this field value to a true null, resulted only in populating the field with a zero or 0. I did some research and found that if I set the Expression Type to Python 3 (instead of Arcade) and then Calculate Field field_name = None    (no quotes around None, gave me actual true null values in the cells of the selected records).

Calculating a true null value in a field using Expression Type Python 3

KoryKramer
Esri Community Moderator

Looky here: BUG-000119064: Calculating a value to null using Arcade returns 0.. 

Pro 2.5 should be out in January.  I guess until then (as I'm assuming others have been doing now anyway) stick with Python, and the 2020 resolution will be to use Arcade to calculate Null!

TristanTaylor
New Contributor

Jimmy Knowles Kory Kramer I know this is very late in the game, with the bug fix coming in January, but I was just able to successfully return true Null in Arcade by just using "return" (without "null")

@

KoryKramer
Esri Community Moderator

What version of Pro?  Calculating on what data type?

I just tried in 2.4.1 on a Long and Text field and using just 'return' returns 0.

0 Kudos
JimmyKnowles
Occasional Contributor II

Kory & Tristan, I tested this in 2.4.2 and using Arcade in the 'Calculate Field' GP tool, it yields the same results as we've seen previously. It appears Tristan is using Attribute Rules. I can confirm that when using Attribute Rules, an Arcade expression of just 'return' does indeed return Null for both Text and Double.

 

I haven't needed this since almost exactly a year ago, so didn't even think if attribute rules would have helped or not.

TristanTaylor
New Contributor

My apologies, Kory, I didn't notice that the problem specifically pertained to Field Calculator until after I posted!

0 Kudos
by Anonymous User
Not applicable

I see some using "return "... is there a way to do this in an attribute rule that is an "edit return"?

return {
    'result': $feature.attribute,
    'edit': [
        {
            'className': 'anotherFeatureClass'
            'updates': [
                {
                    'globalID': objectsGlobalID,
                    'attributes': {
                        'anotherFeaturesAttribute': null // i'd like to update the other feature with "<Null>"
                    }
                }
            ]
        }
    ]
0 Kudos
TL2
by
Regular Contributor

Xander Bakker‌  I have the above question too.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi T L  and Caleb Melies ,

I'm just wondering, if you follow the advise of ttaylo13  and just leave it blank, does that work?

return {
    'result': $feature.attribute,
    'edit': [
        {
            'className': 'anotherFeatureClass', 
            'updates': [
                {
                    'globalID': objectsGlobalID,
                    'attributes': {
                        'anotherFeaturesAttribute': 
                    }
                }
            ]
        }
    ]
}