Select to view content in your preferred language

Problem with Arcade Expression for Pop-Ups

2566
12
07-02-2020 06:44 AM
BrianE
by
Frequent Contributor

New to Arcade and have been exploring it for the last week or so. I have run into an issue with a pop-up.

I am mapping the locations of numerous companies. Some have one location, others have up to six locations. I am writing an expression that will list the locations and their corresponding square footage. So, a company with just one location will have just one line with their address and SF, companies with two locations will have 2 lines (one line for each location), etc.

This is what I have so far:

$feature["ADDRESS_1"] + "  (" + Text($feature["SQUARE_FEET_1"], '#,###') + " RSF)" + TextFormatting.NewLine +

$feature["ADDRESS_2"] + "  (" + Text($feature["SQUARE_FEET_2"], '#,###') + " RSF)" + TextFormatting.NewLine +

$feature["ADDRESS_3"] + "  (" + Text($feature["SQUARE_FEET_3"], '#,###') + " RSF)" + TextFormatting.NewLine +

$feature["ADDRESS_4"] + "  (" + Text($feature["SQUARE_FEET_4"], '#,###') + " RSF)" + TextFormatting.NewLine +

$feature["ADDRESS_5"] + "  (" + Text($feature["SQUARE_FEET_5"], '#,###') + " RSF)" + TextFormatting.NewLine +

$feature["ADDRESS_6"] + "  (" + Text($feature["SQUARE_FEET_6"], '#,###') + " RSF)" + TextFormatting.NewLine

 

I cannot figure out how to have the pop up display ONLY the lines with their locations. I tried messing around with the DefaultValue function but that didn't give me the result I needed.

I have attached a jpeg with current and desired pop-up appearance.

Thanks

Tags (1)
0 Kudos
12 Replies
KenBuja
MVP Esteemed Contributor

You should run a check to see if a location has additional addresses before adding the text.

var output = $feature["ADDRESS_1"] + "  (" + Text($feature["SQUARE_FEET_1"], '#,###') + " RSF)" + TextFormatting.NewLine
if (!IsEmpty(feature["ADDRESS_2"]){
  output += $feature["ADDRESS_2"] + "  (" + Text($feature["SQUARE_FEET_2"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
if (!IsEmpty(feature["ADDRESS_3"]){
  output += $feature["ADDRESS_3"] + "  (" + Text($feature["SQUARE_FEET_3"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
// and so on...
0 Kudos
BrianE
by
Frequent Contributor

Thanks Ken. Some companies have multiple addresses and some do not. They are all part of the same feature layer. Just tried your suggestion and got:

Parse Error:Line 2: Unexpected token {

0 Kudos
KenBuja
MVP Esteemed Contributor

Argh...a forgotten parenthesis. Try this...

var output = $feature["ADDRESS_1"] + "  (" + Text($feature["SQUARE_FEET_1"], '#,###') + " RSF)" + TextFormatting.NewLine
if (!IsEmpty(feature["ADDRESS_2"])){
  output += $feature["ADDRESS_2"] + "  (" + Text($feature["SQUARE_FEET_2"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
if (!IsEmpty(feature["ADDRESS_3"])){
  output += $feature["ADDRESS_3"] + "  (" + Text($feature["SQUARE_FEET_3"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
0 Kudos
BrianE
by
Frequent Contributor

Still no luck. Getting this error now:

Execution Error:Runtime Error: Cannot call member property on object of this type.   

0 Kudos
BrianE
by
Frequent Contributor

Line 2 and 5 above were missing a "$" sign. I put that in there and received no error messages. However, now it returns blanks for all addresses

0 Kudos
KenBuja
MVP Esteemed Contributor

Ah, sorry about that. Do you have a return statement at the end? I wasn't sure if you had additional information you were adding for the other pieces in your popup or if this was a separate expression.

var output = $feature["ADDRESS_1"] + "  (" + Text($feature["SQUARE_FEET_1"], '#,###') + " RSF)" + TextFormatting.NewLine
if (!IsEmpty($feature["ADDRESS_2"])){
  output += $feature["ADDRESS_2"] + "  (" + Text($feature["SQUARE_FEET_2"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
if (!IsEmpty($feature["ADDRESS_3"])){
  output += $feature["ADDRESS_3"] + "  (" + Text($feature["SQUARE_FEET_3"], '#,###') + " RSF)" + TextFormatting.NewLine 
}
return output
0 Kudos
BrianE
by
Frequent Contributor

I didn't have a return statement. Sorry, I am very new to this. Just tried with a return statement and am getting same result that I had originally (see screenshot). And yes, the other pieces in the pop up are from separate expressions.

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you post your code and a snapshot of your data?

0 Kudos
BrianE
by
Frequent Contributor

Sure. See below. That is for the Addresses. Screenshot of data from Pro.

var output = $feature["ADDRESS_1"] + " (" + Text($feature["SQUARE_FEET_1"], '#,###') + " RSF)" + TextFormatting.NewLine
if (!IsEmpty($feature["ADDRESS_2"])){
output += $feature["ADDRESS_2"] + " (" + Text($feature["SQUARE_FEET_2"], '#,###') + " RSF)" + TextFormatting.NewLine
}
if (!IsEmpty($feature["ADDRESS_3"])){
output += $feature["ADDRESS_3"] + " (" + Text($feature["SQUARE_FEET_3"], '#,###') + " RSF)" + TextFormatting.NewLine
}
if (!IsEmpty($feature["ADDRESS_4"])){
output += $feature["ADDRESS_4"] + " (" + Text($feature["SQUARE_FEET_4"], '#,###') + " RSF)" + TextFormatting.NewLine
}
if (!IsEmpty($feature["ADDRESS_5"])){
output += $feature["ADDRESS_5"] + " (" + Text($feature["SQUARE_FEET_5"], '#,###') + " RSF)" + TextFormatting.NewLine
}
if (!IsEmpty($feature["ADDRESS_6"])){
output += $feature["ADDRESS_6"] + " (" + Text($feature["SQUARE_FEET_6"], '#,###') + " RSF)" + TextFormatting.NewLine
}
return output

0 Kudos