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:
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
Solved! Go to Solution.
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';
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;
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
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';
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'
}
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