Select to view content in your preferred language

Help with Arcade If else statement

219
6
Jump to solution
a month ago
Labels (1)
Jmoll
by
Occasional Contributor

Please help me find the error in my code. I am trying to generate a link in a popup based on certain criteria for the address. I got it to work for one specific case but when I try the if else the code won't run.

if(($feature.STR_TYPE == "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE == "AV") && ($feature.PRE_DIR = NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave";}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+"%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR = NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+;}
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You were missing a extra "=" on line 3

$feature.PRE_DIR == NULL

if(($feature.STR_TYPE == "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE == "AV") && ($feature.PRE_DIR == NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave";}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+"%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR = NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+;}

 

 

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

When posting code, please us the "Insert/Edit code sample" button. It's much easier to read and analyze rather that trying to replicate it from an image

JoshuaBixby
MVP Esteemed Contributor

It also helps to post the specific error message rather than saying "the code won't run."

Although ArcGIS Arcade looks like JavaScript, it isn't JavaScript.  There is no "else if" construct in Arcade, refer to If - else | ArcGIS Arcade | Esri Developer.

Additionally, there is almost always a better logical construct/function than using large if/else blocks.  I encourage you to explore using When.

0 Kudos
KenBuja
MVP Esteemed Contributor

You can use "else if" in a if/else block, but I do agree that using When is a better solution.

0 Kudos
Jmoll
by
Occasional Contributor

Thank you both, I fixed the error and will try to use When instead!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Ken, interesting, their documentation implies it isn't supported since they fully nest a single if/else statement within the else portion of another statement instead of using "else if" directly.  I know there are certain common JavaScript constructs that Arcade doesn't support, I just thought "else if" was another.

0 Kudos
KenBuja
MVP Esteemed Contributor

You were missing a extra "=" on line 3

$feature.PRE_DIR == NULL

if(($feature.STR_TYPE == "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE == "AV") && ($feature.PRE_DIR == NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20ave"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20ave";}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR != NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+$feature.PRE_DIR+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+"%20"+$feature.PRE_DIR;}
else if (($feature.STR_TYPE != "AV") && ($feature.PRE_DIR = NULL)){
  return "http://fileshare.napoleonohio.com/vfolder_frame.ghp?vfolder=/Address%20Files/"+$feature.STR_NAME+"%20+"+$feature.PRE_TYPE+"%20"+"/"+$feature.STR_NUM+"%20"+$feature.STR_NAME+"%20"$feature.PRE_TYPE+;}