I have Python calculate field expression (.cal file) that does this but I'm trying to migrate it to Arcade.
It's not working. The number part is not incrementing and I guess it has to do with me not being able of defining 'rec' as a global variable.
This is the Python expression. How do I migrate the 'global rec' line to Arcade?
#Params
val_counter = 2498
prefix = 'PP_'
interval = 1
# -------------------------------------------
# Function
rec=0
def SetIDcode(val_counter, prefix, interval):
global rec
if (rec == 0):
rec = val_counter
else:
rec += interval
return (prefix+ str(rec))
In Python this is the shortest code I could come up with that does what you seem to want.
rec=2497
def fn():
rec += 1
return 'pp_'+str(rec)
You can dress it up with comments and constants and pass in variables as args but this is all you need.
I could be all wrong on this but after experimenting I conclude that in Arcade you just get a simple expression and each time the field calculator is invoked on a row in your table it will set all variables back to their initial state. In the field calculator there is no global memory.
For what you are trying to do therefore, use the Python.
Therefore there is no equivalent that I can give you, you will just get the same value on each row.