Select to view content in your preferred language

Arcade Script for Populating the Full Street Name using Attribute Rules

327
4
Jump to solution
07-26-2024 11:32 AM
nidz4evr
Emerging Contributor

Hello Everyone,

Forgive my incompetence here. But I can't write complex script in arcade. Your help is really appreciated. 

Is anyone can help or has a script in populating the full street name with the NENA schema? Some of the fields are empty (or/ Null), so I don't how to remove the extra space when concatenating all the fields using the attribute rules. 

nidz4evr_0-1722018205346.png

Thank you for your help!

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
NicoleJohnson
Occasional Contributor

Thanks for letting me know this didn't work perfectly (I also mocked up your data, tried it, and got the same result). For now, instead of return fullName you can do return Trim(fullName). This will remove spaces at the beginning and end of your string. You can also remove the empty single quotes from var fullName = '', to just be var fullName (i.e., you don't have to give any hint of what the variable is going to store until you actually use it--something I learned today).

Edit: of course as soon as I hit post, I realize what the error is, and it's SO simple. For the Cane Creek record, imagine you're going through field by field evaluating whether the value is null or not. All are null until you hit street name, and since that returns true, it's going to go to the second line of that If statement, and return a space followed by the street name.

So, instead, add the spaces after the field value:

var fullName

if(IsEmpty($feature.st_premod)==false){
fullName += $feature.st_premod + " "
}
if(IsEmpty($feature.st_predir)==false){
fullName += $feature.st_predir + " "
}
if(IsEmpty($feature.st_pretyp)==false){
fullName += $feature.st_pretyp + " "
}
if(IsEmpty($feature.st_presep)==false){
fullName += $feature.st_presep + " "
}
if(IsEmpty($feature.st_name)==false){
fullName += $feature.st_name + " "
}
if(IsEmpty($feature.st_postyp)==false){
fullName += $feature.st_postyp + " "
}
if(IsEmpty($feature.st_posdir)==false){
fullName += $feature.st_posdir + " "
}
if(IsEmpty($feature.st_posmod)==false){
fullName += $feature.st_posmod
}

return fullName

View solution in original post

4 Replies
NicoleJohnson
Occasional Contributor

Hi,

One way to do this very simply is to just check whether the field is null, and if it isn't, add it to a string that you build over the different fields.

Something like this (replace with your field names):

 

var fullName = ''

if(IsEmpty($feature.NAME)==false){
  fullName += $feature.NAME
}

if(IsEmpty($feature.FETYPE)==false){
  fullName += " " + $feature.FETYPE
}

return fullName
 
 
nidz4evr
Emerging Contributor

Hi @NicoleJohnson 

I really appreciate your respond. Thank you very much. And it really works. However, I noticed that there is one space before the value, if the first field '$feature.st_premod' is null, as shown in the screenshot below with red line. But with value, its perfect. And I can't figure out how to remove that space.

nidz4evr_1-1722358020070.png

Your additional input is very much appreciated on how to remove the space with my current syntax? 

var fullName = ''

if(IsEmpty($feature.st_premod)==false){
fullName += $feature.st_premod
}

if(IsEmpty($feature.st_predir)==false){
fullName += " " + $feature.st_predir
}
if(IsEmpty($feature.st_pretyp)==false){
fullName += " " + $feature.st_pretyp
}
if(IsEmpty($feature.st_presep)==false){
fullName += " " + $feature.st_presep
}
if(IsEmpty($feature.st_name)==false){
fullName += " " + $feature.st_name
}
if(IsEmpty($feature.st_postyp)==false){
fullName += " " + $feature.st_postyp
}
if(IsEmpty($feature.st_posdir)==false){
fullName += " " + $feature.st_posdir
}
if(IsEmpty($feature.st_posmod)==false){
fullName += " " + $feature.st_posmod
}
return fullName

0 Kudos
NicoleJohnson
Occasional Contributor

Thanks for letting me know this didn't work perfectly (I also mocked up your data, tried it, and got the same result). For now, instead of return fullName you can do return Trim(fullName). This will remove spaces at the beginning and end of your string. You can also remove the empty single quotes from var fullName = '', to just be var fullName (i.e., you don't have to give any hint of what the variable is going to store until you actually use it--something I learned today).

Edit: of course as soon as I hit post, I realize what the error is, and it's SO simple. For the Cane Creek record, imagine you're going through field by field evaluating whether the value is null or not. All are null until you hit street name, and since that returns true, it's going to go to the second line of that If statement, and return a space followed by the street name.

So, instead, add the spaces after the field value:

var fullName

if(IsEmpty($feature.st_premod)==false){
fullName += $feature.st_premod + " "
}
if(IsEmpty($feature.st_predir)==false){
fullName += $feature.st_predir + " "
}
if(IsEmpty($feature.st_pretyp)==false){
fullName += $feature.st_pretyp + " "
}
if(IsEmpty($feature.st_presep)==false){
fullName += $feature.st_presep + " "
}
if(IsEmpty($feature.st_name)==false){
fullName += $feature.st_name + " "
}
if(IsEmpty($feature.st_postyp)==false){
fullName += $feature.st_postyp + " "
}
if(IsEmpty($feature.st_posdir)==false){
fullName += $feature.st_posdir + " "
}
if(IsEmpty($feature.st_posmod)==false){
fullName += $feature.st_posmod
}

return fullName

nidz4evr
Emerging Contributor

You're awesome! Thank you very much @NicoleJohnson  and thank you for sharing your knowledge. Have a great day!