Select to view content in your preferred language

Arcade Expressions: Creating an expression for labels with multiple fields

1177
2
Jump to solution
10-27-2023 07:05 AM
Labels (1)
GrantCountyGISSup
Occasional Contributor

I'm using ArcGIS Pro 3.1.3 and I will start out by saying I am a beginner with computer languages.  

Currently, I am trying to write an expression for labels using Arcade.  I can get the Else If statements to be valid expressions. 

if ($feature.CTV == "C"){
return "City"
}
else if ($feature.CTV == "V"){
return "Village"
}
else if ($feature.CTV == "T"){
return "Township"
}

GrantCountyGISSup_0-1698415119623.png

However, this is only one part of the Label. I need to add MCD_Name to the beginning to get an out put like Paris Township.  When I try to add it:

$feature.MCD_NAME + TextFormatting.NewLine +

if ($feature.CTV == "C"){
return "City"
}
else if ($feature.CTV == "V"){
return "Village"
}
else if ($feature.CTV == "T"){
return "Township"
}

I get an Error stating its an Invalid Expression. Error on line 3. Reserved keyword used.

I tried adding parenthesis, quotations, brackets etc.. (again I am no expert on computer language) and nothing seemed to work.  I looked at other examples and such but I could not seem to find this kind of scenario.

Thank you in advance!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

What you'll want to do is to create a variable that holds the first part of your label and use that to append the city type

var output = $feature.MCD_NAME + TextFormatting.NewLine;

if ($feature.CTV == "C"){
  output += "City";
}
else if ($feature.CTV == "V"){
  output += "Village";
}
else if ($feature.CTV == "T"){
  output += "Township";
}

return output;

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

What you'll want to do is to create a variable that holds the first part of your label and use that to append the city type

var output = $feature.MCD_NAME + TextFormatting.NewLine;

if ($feature.CTV == "C"){
  output += "City";
}
else if ($feature.CTV == "V"){
  output += "Village";
}
else if ($feature.CTV == "T"){
  output += "Township";
}

return output;

 

GrantCountyGISSup
Occasional Contributor

Awesome! I appreciate your input, it worked like a charm!

0 Kudos