Select to view content in your preferred language

arcade if, else (do nothing)

15175
7
Jump to solution
07-28-2020 12:48 AM
Gisbert61
Frequent Contributor

I'm filling in some missing attributes in a feature layer using 'calculate field' and I tried:

and this works, kind of. Empty fields gets filled in with '3' but any field already filled are emptied and <null> afterwards.

So for the moment I have:

which covers all possible values (in the coded value domain on this attribute). This works but is cumbersome.

What I would like to do is something like

How can I achieve this ... else do nothing ... ?

Thanks in advance for your time.

Bert Kraan

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoshuaSharp-Heward
Frequent Contributor

Hi Bert,

You can simply add the line "return $feature.verharding" to the else clause, which means for all other values it will just return the existing value.

Note, a better way to do this would be to use the IIF arcade function detailed here: Logical Functions | ArcGIS for Developers  to do it in one line!

View solution in original post

7 Replies
JoshuaSharp-Heward
Frequent Contributor

Hi Bert,

You can simply add the line "return $feature.verharding" to the else clause, which means for all other values it will just return the existing value.

Note, a better way to do this would be to use the IIF arcade function detailed here: Logical Functions | ArcGIS for Developers  to do it in one line!

HåkonDreyer
Esri Contributor

Hi, Bert

Guess the easiest will be to select all null values using Select by attributes, and then run the calculation using your initial code on the selected set.

Alternatively, you may send the value to the field calculator using:

Egge-Jan_Pollé
MVP Alum

Hi Bert Kraan,

I was actually going to come up with the first solution given by Joshua Sharp-Heward, but from the same answer I learned about the IIf() function.

That's why it is so good to follow this forum, to learn a little every day (very kaizen!).

So, to wrap up:

Simple solutionOne line solution
if (IsEmpty($feature.verharding)) {
    return 3;
} else {
    return $feature.verharding;
}
IIf (IsEmpty($feature.verharding), 3, $feature.verharding);‍‍‍‍

HTH,

Egge-Jan

MDB_GIS
Frequent Contributor

Long out of date, but thanks to you and @JoshuaSharp-Heward for mentioning IIF statements. I was able to greatly streamline some of my attribute rules using this newfound knowledge!

0 Kudos
Gisbert61
Frequent Contributor

Thanks all for three great answers from all over the globe!

Bert

JJ_Reyes
Frequent Contributor

This is a good solution, but it does change the edit date on the records as if they were actually calculated. I wonder if there is another way to do this (when selecting a set first is not an option)?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I am pretty sure you are out of luck, and it isn't just an Arcade limitation.  Calculate Field has to return something for each record, there is no way to tell Calculate Field to stop processing the current record and move onto the next.

0 Kudos