arcade if, else (do nothing)

10174
5
Jump to solution
07-28-2020 12:48 AM
BertKraan1
Occasional Contributor III

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
Occasional Contributor III

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

5 Replies
JoshuaSharp-Heward
Occasional Contributor III

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 Regular Contributor

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

BertKraan1
Occasional Contributor III

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

Bert

JJ_Reyes
Occasional 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