Only part of my Arcade expression is rendered correctly in an ArcGIS Dashboards list

969
2
Jump to solution
05-16-2021 12:13 PM
ShaneBradt
New Contributor III

I have been working with ArcGIS Dashboards for the past year, but I finally decided to dip my toe into the world of Arcade this past week. I am trying to use Arcade to accomplish two tasks on the same ArcGIS Dashboards list:

1) look up the acreage of a parcel in a field and either show text "size not reported" or a formatted version of the acreage depending on the value (-999 indicates the size was not reported)

2) format the background color of each item in the list based on the access status of that parcel (values range from 1 to 5)

After a bunch of googling and hacking away, I was able to produce code which accomplishes both tasks. However, only the first task displayed in the Advanced formatting winds up getting applied:

access.png

acres.png

It seems to me that something in my formatting is causing the reading of the code to stop at the end of whatever section of the script is on top. I tried looking at many examples that Esri and others provided, but I just can't figure out what is happening. I tried removing and adding brackets, but nothing I've tried has solved the problem.

I realize that I am likely missing something simple, but I'm all out of ideas about how to troubleshoot on my own. Any advice / suggestions would be greatly appreciated!

Thanks so much - Shane

In case it's helpful, here's the code:

if ($datapoint.ACCESS == 1){
  return { 
        backgroundColor: '#BED7EA',
    };
} else if ($datapoint.ACCESS == 2) {
  return { 
        backgroundColor: '#DDBDDE',
    };
} else if ($datapoint.ACCESS == 3) {
  return { 
        backgroundColor: '#FFD9AA',
    };
} else if ($datapoint.ACCESS == 4) {
  return { 
        backgroundColor: '#aaaaaa',
    };
} else if ($datapoint.ACCESS == 5) {
  return { 
        backgroundColor: '#aaaaaa',
    };
}


var acres = iif($datapoint.RSIZE<0, 'size not reported', Text(Round(Number($datapoint.RSIZE),1),"#,###.#"));

    return {
 	    attributes: {
            realacres: acres
 	}
}

 

0 Kudos
1 Solution

Accepted Solutions
Jelle_Stu_PR
Occasional Contributor II

You are nearly there. I think your issue is that you have two return statements. The output of your arcade script in ArcGIS Dashboard can only return one value/object. You need to just have one return statement that combines both. 

Save the desired Hexadecimal as a variable and return it at the end through the backgroundColor key.

 

 

if ($datapoint.ACCESS == 1){
    var my_color = '#BED7EA',
} else if ($datapoint.ACCESS == 2){
     var my_color =  '#DDBDDE',
} else if ($datapoint.ACCESS == 3){
 ...
}

var acres = iif($datapoint.RSIZE<0, 'size not reported', Text(Round(Number($datapoint.RSIZE),1),"#,###.#"));

return{
    backgroundColor: my_color,
    attributes: {
        realacres: acres
    }
}

 

 


View solution in original post

2 Replies
Jelle_Stu_PR
Occasional Contributor II

You are nearly there. I think your issue is that you have two return statements. The output of your arcade script in ArcGIS Dashboard can only return one value/object. You need to just have one return statement that combines both. 

Save the desired Hexadecimal as a variable and return it at the end through the backgroundColor key.

 

 

if ($datapoint.ACCESS == 1){
    var my_color = '#BED7EA',
} else if ($datapoint.ACCESS == 2){
     var my_color =  '#DDBDDE',
} else if ($datapoint.ACCESS == 3){
 ...
}

var acres = iif($datapoint.RSIZE<0, 'size not reported', Text(Round(Number($datapoint.RSIZE),1),"#,###.#"));

return{
    backgroundColor: my_color,
    attributes: {
        realacres: acres
    }
}

 

 


ShaneBradt
New Contributor III

Thanks so much @Jelle_Stu_PR! That did the trick.

I tried using variables to make it work in a bunch of different ways, but all approaches involved more than one return statement. Seems like you need to be more thoughtful in Dashboards (all Arcade code in one place) as compared to ArcGIS Online (where you can create and refer to many expressions, and where I saw the greatest number of examples to follow). 

Not only did your tip help with this Dashboard, it will undoubtedly help in many to come. Thanks again!

0 Kudos