Select to view content in your preferred language

Custom Label Arcade multiple conditions

510
3
Jump to solution
07-21-2022 08:30 AM
Labels (1)
KWilliams
Occasional Contributor

Hello - I am attempting to write what should be simple arcade code, but I just don't have the experience. I know how I'd write it in Python, but Arcade is throwing me.

My first two statements work fine. But I need an option for when these two fields are BOTH == 'Yes', the code returns 'OHG Slack Span'. Any help will be greatly appreciated!

if ($feature["Overhead_Guy"] == 'Yes'){
return 'OHG'
}
if ($feature["Slack_Span"] == 'Yes'){
return 'Slack Span'
}

 

I found a technical support page Use multiple conditions that makes the answer seem obvious but putting the || between my conditions is throwing the 'unexpected token ||' error

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Don't use a return in each of the if statements, but use a variable. Putting a space after the OHG in the first statement makes it ready for the next statement, but it will get trimmed away if not needed in the return.

var output = '';
if ($feature["Overhead_Guy"] == 'Yes'){
 output = 'OHG ';
}
if ($feature["Slack_Span"] == 'Yes'){
  output += 'Slack Span'
}
return Trim(output);

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

Don't use a return in each of the if statements, but use a variable. Putting a space after the OHG in the first statement makes it ready for the next statement, but it will get trimmed away if not needed in the return.

var output = '';
if ($feature["Overhead_Guy"] == 'Yes'){
 output = 'OHG ';
}
if ($feature["Slack_Span"] == 'Yes'){
  output += 'Slack Span'
}
return Trim(output);

 

KWilliams
Occasional Contributor

That worked first try! Thank you so much! 

0 Kudos
KenBuja
MVP Esteemed Contributor

Glad to help. Don't forget to click the "Accept as Solution" button

0 Kudos