Select to view content in your preferred language

Why is my Arcade expression only interpreted once unless I include an attribute value?

925
2
Jump to solution
12-28-2018 10:01 AM
EricaPfister
New Contributor III

I am using the Calculate Field tool generate a random number between 0 and 180. I can do this with a Python codeblock. The following gives me a different random integer in each row:

def randomize():
    import random
    return random.randint(0,180)‍‍‍‍‍‍‍‍‍

I thought I could do it with an Arcade expression:

Round(Random() * 180, 0)‍‍

However, this gave me only one random number: each row had the same value, which isn't what I wanted. Apparently, the Arcade expression was calculated only once and its result was copied.

I found an awkward workaround, by including the OBJECTID in the expression:

($feature.OBJECTID * 0) + Round(Random() * 180, 0)‍‍

This, just like the Python codeblock, gave me different random numbers in each row. However, the Python codeblock didn't require me to specify a "dummy" value.

(Side note: including the attribute value didn't run significantly more slowly, even though there are thousands of rows in this feature class.)

Is it "as expected" behavior that an Arcade expression will only be interpreted once unless an attribute is included in the expression? It wasn't intuitively obvious to me.

0 Kudos
1 Solution

Accepted Solutions
KoryKramer
Esri Community Moderator

I can't say for sure why it doesn't work in Pro 2.2 (I think lack of cursor support), but when I set this up in Pro 2.3 (beta), I see this:

Hit Run again:

And again, just for good measure 

I don't think cursors are supported using Arcade until Pro 2.3.

View solution in original post

2 Replies
KoryKramer
Esri Community Moderator

I can't say for sure why it doesn't work in Pro 2.2 (I think lack of cursor support), but when I set this up in Pro 2.3 (beta), I see this:

Hit Run again:

And again, just for good measure 

I don't think cursors are supported using Arcade until Pro 2.3.

EricaPfister
New Contributor III

Gotcha -- I'm in Pro 2.1.3, so this is definitely not expected behavior but it will be addressed whenever we're able to upgrade our Pro version. Thank you!

0 Kudos