Select to view content in your preferred language

Arcade Expression to Calculate Field

964
2
Jump to solution
11-02-2023 07:53 AM
Labels (1)
JanelleShank
Emerging Contributor

Hello everyone!  I am looking for some help with writing an Arcade Expression. I have tried using If Else statements, but my results do not seem to be adding about. For example, I trying to trying an expression that goes through multiple fields (see table below) and finds the word "NO". Next, if any of the fields have "NO" in them, the new field will say "Non Compliant". 

JanelleShank_0-1698936777402.png

Thank you!

 

Best,

Janelle

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The way to do that is to make a list of the fields you want to check and loop through that list to check if that field contains "No". You'll have to use the Expects function when using a variable for the field name.

Expects($feature, 'field1', 'field2', 'field3') //replace these with your field names
var fields = ['field1', 'field2', 'field3'] //replace these with your field names
var compliance = 'Compliant'
for (var i in fields) {
  if ($feature[fields[i]] == 'No') compliance = 'Not Compliant' //This is case sensitive, so 'NO' does not equal 'No'
}
return compliance

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

The way to do that is to make a list of the fields you want to check and loop through that list to check if that field contains "No". You'll have to use the Expects function when using a variable for the field name.

Expects($feature, 'field1', 'field2', 'field3') //replace these with your field names
var fields = ['field1', 'field2', 'field3'] //replace these with your field names
var compliance = 'Compliant'
for (var i in fields) {
  if ($feature[fields[i]] == 'No') compliance = 'Not Compliant' //This is case sensitive, so 'NO' does not equal 'No'
}
return compliance
0 Kudos
JanelleShank
Emerging Contributor

Thank you!

0 Kudos