Using Arcade instead of Python to Field Calculate If-Else-Pass (Do Nothing)

490
7
Jump to solution
07-14-2021 11:59 PM
Labels (2)
LindsayRaabe_FPCWA
Regular Contributor

So I know that in python you can write if-else statements and use "pass" to skip doing something if that is desired. I've trawled the web on Arcade and can't find an equivalent to the pass option in python. Does this exist? 

 

i.e. - I have a feature class and table joined together. I want to compare 2 fields to see if they match (if FieldA == FieldB). If they match, do nothing (pass), if not, return FieldB. 

I know I could simply return FieldA (as per this solution in this post) but I want to see if by skipping instead of returning FieldA, it might improve the speed of the calculation if it can skip values instead of returning the original value???

 

P.S. I couldn't actually get it to work in python - it didn't seem to like the joined field names (i.e. Table1.FieldA == Table2.csv.FieldA). I did get it to work on a an un-joined feature class (i.e. FieldA == FieldB). I'm guessing it was the "dots" between the table name and the field name that was confusing it. 

Lindsay Raabe
Forest Products Commission WA
0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Esteemed Contributor

I think 'continue' is the Arcade equivalent to Python's 'pass'.

That should just about do it....

View solution in original post

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor
LindsayRaabe_FPCWA
Regular Contributor

Thanks @DanPatterson I had seen that post. I suppose that wasn't quite what I was looking for in that it returns an existing value instead of passing (or "continuing") onto the next row - I couldn't confirm if it was still recalculating the field with the existing value or actually skipping the row. 

Lindsay Raabe
Forest Products Commission WA
0 Kudos
JoeBorgione
MVP Esteemed Contributor

I think 'continue' is the Arcade equivalent to Python's 'pass'.

That should just about do it....
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

Hi @JoeBorgione I think this is what I'm looking for. Trying to implement now and see how it performs, but struggling with my newness to arcade and getting my head around the structure. 

var row1 = $feature['featureclass.Work_Centre']
var row2 = $feature['jointable.csv.WorkCentre']
for(var r in row1) {
  if (r==row2) continue;

  if (r!=row2);
  row2;
}

Essentially in the code section of the Calculate Field tool I'm, trying to read 2 fields in a feature class joined to a table and compare the 2 fields. If values match, continue, if not, return value from the join table (row2). Any pointers on where I've gone wrong? It told me it was valid, but when I ran it, all values were calculated as Nulls instead of being left as they were or updated with new values. 

LindsayRaabe_FPCWA_0-1626396028823.png

LindsayRaabe_FPCWA_1-1626396205356.png

 

Lindsay Raabe
Forest Products Commission WA
0 Kudos
JoeBorgione
MVP Esteemed Contributor

I don’t see you returning a value to your expression. I’m responding from my phone so I don’t have anything I can grab for an example. I’ll try to remember you in the morning.

Another thing too, and just like in python, the continue/pass in this case may be syntactically correct but you need to return an actual value instead. 

That should just about do it....
0 Kudos
LindsayRaabe_FPCWA
Regular Contributor

Thanks. I figure it's something simple but struggling to find an example that clearly breaks down the different components in a way I understand. Thought I was returning the value on the 2nd last line, but obviously not. 

Lindsay Raabe
Forest Products Commission WA
0 Kudos
JoeBorgione
MVP Esteemed Contributor

Below is an attribute rule I fire when I create a a site address point .  I don't use arcade for calculations as I prefer Python, but you get the gist of an If/Else and returning a value. This expression basically looks to see if a new point intersects an underlying feature layer; If it does (line 5) it grabs the value in the ZIP_MOD_ID field, other wise it returns null...

 

// Zip Left Right

var zip = FeatureSetByName($datastore,"MSD.SLCOMSD.ZipcodesMSD",["ZIP_MOD_ID"], true)
var intersectLayer = Intersects(zip, Geometry($feature))
if (Count(intersectLayer) > 0) {
    var layer = First(intersectLayer);
    return layer.ZIP_MOD_ID;    
} else {
    return null;
}

 

That should just about do it....