My arcade code is ending in "Execution Error:Runtime Error:" and I'm not sure why

1070
3
Jump to solution
02-23-2022 08:59 AM
EH_Alaska
Occasional Contributor

I'm attempting to change the symbology for the National Bridge Inventory layer. By default, it is set to create symbology based on the Deck Structure field. However, for our purposes we need to base the symbology around an average of Deck Structure, Substructure, and Superstructure. We also want to flag any records where all three of these fields are equal to 5.

I've tried several variations of code, such as using a When statement, creating a function to flag those "5" records, etc. Some have ended in errors, others have produced bad results such as symbolizing everything as "Unknown". Right now, my code consists of several if/else statements:

 

var c = $feature["DECK_COND_058"]
var ss = $feature["SUPERSTRUCTURE_COND_059"]
var sb = $feature["SUBSTRUCTURE_COND_060"]
var avg = AVERAGE($feature["DECK_COND_058"], $feature["SUPERSTRUCTURE_COND_059"], $feature["SUBSTRUCTURE_COND_060"])

if((c == 5) && (ss == 5) && (sb == 5)) {
    "Fair, soon to be poor";
} else if (Round(avg = 9)) {
    "Excellent to good";
} else if (Round(avg = 8)) {
    "Excellent to good";
} else if (Round(avg = 7)) {
    "Excellent to good";
} else if (Round(avg = 6)) {
    "Satisfactory to fair";
} else if (Round(avg = 5)) { 
    "Satisfactory to fair";
} else if (Round(avg = 4)) { 
    "Poor to critical";
} else if (Round(avg = 3)) {
    "Poor to critical";
} else if (Round(avg = 2)) {
    "Poor to critical";
} else if (Round(avg = 1)) {
    "Failed to imminent failure";
} else if (Round(avg = 0)) {
    "Failed to imminent failure";
} else {
    "Unknown";
}

 

 

This returns the following error:

 

Execution Error:Runtime Error:

 

 

I'm not really sure what this means. Any insight? Can you spot any obvious flaws in my code? Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Your conditions need to be written with "==", not "=". The single equals sign would attempt to assign the value to a variable. And it looks like you're trying to check if the rounded average is equal to the value, but you have "avg = 9" inside the Round function.

if (Round(avg) == 9)

Second, your if/else if/else statements have no return in them, so that's probably also going to give you errors.

if (Round(avg) == 9){
return "Excellent to good";
}

As for the code itself, this can be made a bit more concise. Since the variable avg is being rounded every time you use it, you may as well round it off at the start. It also looks like some of your conditions evaluate to the same output text, so you can combine those together.

Finally, you might check out the Where function. As with your if/else if/else statements, conditions in the Where function evaluate in order, so you can simply check if avg is greater than your threshold values.

Here's how I might re-write your expression.

var c = $feature["DECK_COND_058"]
var ss = $feature["SUPERSTRUCTURE_COND_059"]
var sb = $feature["SUBSTRUCTURE_COND_060"]
var avg = Round(Average([c, ss, sb]))

return When(
    c == 5 && s == 5 && sb == 5, 'Fair, soon to be poor',
    avg > 6, 'Excellent to good',
    avg > 4, 'Satisfactory to fair',
    avg > 1, 'Poor to critical',
    avg == 1 || avg == 0, 'Failed to imminent failure',
    'unknown'
)

 

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

Your conditions need to be written with "==", not "=". The single equals sign would attempt to assign the value to a variable. And it looks like you're trying to check if the rounded average is equal to the value, but you have "avg = 9" inside the Round function.

if (Round(avg) == 9)

Second, your if/else if/else statements have no return in them, so that's probably also going to give you errors.

if (Round(avg) == 9){
return "Excellent to good";
}

As for the code itself, this can be made a bit more concise. Since the variable avg is being rounded every time you use it, you may as well round it off at the start. It also looks like some of your conditions evaluate to the same output text, so you can combine those together.

Finally, you might check out the Where function. As with your if/else if/else statements, conditions in the Where function evaluate in order, so you can simply check if avg is greater than your threshold values.

Here's how I might re-write your expression.

var c = $feature["DECK_COND_058"]
var ss = $feature["SUPERSTRUCTURE_COND_059"]
var sb = $feature["SUBSTRUCTURE_COND_060"]
var avg = Round(Average([c, ss, sb]))

return When(
    c == 5 && s == 5 && sb == 5, 'Fair, soon to be poor',
    avg > 6, 'Excellent to good',
    avg > 4, 'Satisfactory to fair',
    avg > 1, 'Poor to critical',
    avg == 1 || avg == 0, 'Failed to imminent failure',
    'unknown'
)

 

- Josh Carlson
Kendall County GIS
EH_Alaska
Occasional Contributor

Hey Josh,

Thank you so much for your response! I tried using the code you wrote and it ended up making everything "Unknown". I then went back to my old code and applied all of your comments and now it's working great! I definitely learned a lot from your response, and I really appreciate that you took the time to write back as I know I'll have to do more coding in the future.

Sincerely,

Ellie

0 Kudos
jcarlson
MVP Esteemed Contributor

Well, I'm glad to hear you got it working!

- Josh Carlson
Kendall County GIS