Select to view content in your preferred language

Arcade Expression Multiple Conditions in IF blocks

1424
5
Jump to solution
04-07-2023 01:08 PM
Labels (1)
Caitlin_Todd_LCOR
New Contributor III

Hi all, 

I'm hoping you can help me out with this Arcade expression. I have an inspection form in ArcGIS FieldMaps that needs to calculate whether or not something is "passing" based on multiple conditions.

I'm having trouble with the nested IF statements failing to calculate in FieldMaps. I need to write an expression to say:

Slope 1 is passing IF slope percentage is not null and less than or equal to 8.3, BUT if the style is Blended Transition or Cut Through, then it is only passing if the slope percentage is less than or equal to 5.
 

My expression so far is: 

if (($feature.ramp_style =='Blended_Transition'||$feature.ramp_style == 'Cut_Through')&&($feature.Run1_Slope_PC <=5) && $feature.Run_Slope1_PC!=null) {
  return "Pass"
} else if (($feature.ramp_style!='Blended_Transition' && $feature.ramp_style != 'Cut_Through')&&($feature.Run_Slope1_PC>0 && $feature.Run_Slope1_PC<=8.3 && $feature.Run_Slope1_PC!=null)) {
  return "Pass"
} else {
  return "Fail"
}

The only error message I get is "Failed to Calculate" and "Exploded Map Package" in the FieldMaps troubleshooting logs.

I don't have much experience with nested if-else blocks so maybe I have my grammar wrong?

Thanks for all your help, 

Caitlin

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Ah, I had misread the requirements. This should work

if (IsEmpty($feature.Run_Slope1_PC)) return 'Fail'
if ($feature.ramp_style == 'Blended_Transition' || $feature.ramp_style == 'Cut_Through') {
  if ($feature.Run_Slope1_PC <= 5) return 'Pass'
} else if ($feature.Run_Slope1_PC <= 8.3) return 'Pass'
return 'Fail';

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

Give this a try. It is using nested ifs, but it might be easier to understand.

var output = 'Fail';
if (!IsEmpty($feature.feature.Run_Slope1_PC)) {
   if ($feature.feature.Run_Slope1_PC <= 5) {
      if ($feature.ramp_style == 'Blended_Transition' || $feature.ramp_style == 'Cut_Through') output = 'Pass'
   } else if ($feature.feature.Run_Slope1_PC <= 8.3) output = 'Pass'
}
return output;

 

0 Kudos
Caitlin_Todd_LCOR
New Contributor III

Hi thanks so much for the suggestion! Unfortunately it only halfway worked for what I needed it to do. It does let a slope be passing if the style is Blended Transition or Cut Through and <= 5, but it fails to calculate when the style isn't one of those two. 

I'll keep trying with the format you provided and see if I can find a way to get it to work

0 Kudos
KenBuja
MVP Esteemed Contributor

Ah, I had misread the requirements. This should work

if (IsEmpty($feature.Run_Slope1_PC)) return 'Fail'
if ($feature.ramp_style == 'Blended_Transition' || $feature.ramp_style == 'Cut_Through') {
  if ($feature.Run_Slope1_PC <= 5) return 'Pass'
} else if ($feature.Run_Slope1_PC <= 8.3) return 'Pass'
return 'Fail';
DavidPike
MVP Frequent Contributor

I've tried to simplify the logic by using return statements.

tested in https://developers.arcgis.com/arcade/playground/ with dummy variables and seems to work as intended.

 

//dummy values for testing 
var Run_Slope1_PC = 7
var ramp_style = 'Blended_Transition'

//if empty FAIL
if (IsEmpty(Run_Slope1_PC)) {
    return 'Fail'
}

//if >5 and (blendedT or CutThru) FAIL
if (Run_Slope1_PC > 5 && (ramp_style == 'Blended_Transition' || ramp_style == 'Cut_Through')) { 
    return 'Fail'
}

//anything else <=8.3 PASS
if (Run_Slope1_PC <= 8.3) {
    return 'Pass'
}

else {
    return 'Fail'
}

 

0 Kudos
Caitlin_Todd_LCOR
New Contributor III

David and Ken, both of those worked! Thank you both so much! You are Arcade geniuses. 

I put Ken's as the solution since it's fewer lines.

Hope your weeks go smoothly 

Caitlin

0 Kudos