Help with Arcade If else statement

2584
6
Jump to solution
12-16-2024 05:54 AM
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+;}
This widget could not be displayed.
This widget could not be displayed.
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

This widget could not be displayed.
This widget could not be displayed.
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

This widget could not be displayed.
This widget could not be displayed.
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.

This widget could not be displayed.
This widget could not be displayed.
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.

This widget could not be displayed.
This widget could not be displayed.
Jmoll
by
Occasional Contributor

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

This widget could not be displayed.
This widget could not be displayed.
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.

This widget could not be displayed.
This widget could not be displayed.
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+;}

 

 

This widget could not be displayed.
This widget could not be displayed.