Select to view content in your preferred language

Get Feature Layer with Dashboard Data expression

867
1
Jump to solution
06-27-2023 04:45 PM
MichaelMacRae
New Contributor II

I am trying to create a Data Expression within an AGO Dashboard (current dashboard, not classic) serial chart and I am having trouble getting a layer so I cna build an expression around it. I have seen numerous examples using the following example:

// Represents the ArcGIS Online portal instancevar 
agol = Portal("https://www.arcgis.com");

// references a layer with its ID from a specified portal instance
var
layer = FeatureSetByPortalItem(agol, "7b1fb95ab77f40bf8aa09c8b59045449", 0, ["*"], false);

I have ran the expression using my own organizational account and item id but it returns NULL:

MichaelMacRae_0-1687909035494.png

I believe the issue is, I do not have ArcGIS Portal, so I don't believe I can use the FeatureSetByPortalItem function.

I have tried some of the other functions (i.e. FeatureSetById, FeatureSetByName, etc) to get my feature service, but I keep getting errors. It does seem to recognize the map in my dashboard using '$map'. I have also tried '$datastore'.

MichaelMacRae_1-1687909309354.png

I am at a bit of a loss. I have no idea how to get a feature service into my expression to I can build more expression. Any suggestions as to how to do this?

0 Kudos
1 Solution

Accepted Solutions
MichaelMacRae
New Contributor II

SO, I figured out where I was going wrong. I am fairly new to Arcade, but have a solid scripting background, so I shouldn't have missed some things.

First, the FeatureSetByPortalItem function does work, regardless whether or not you have ArcGIS Portal. It's just a function call for an item in your given portal. So, the following works:

agol = Portal("https://www.arcgis.com");
layer = FeatureSetByPortalItem(agol, "7b1fb95ab77f40bf8aa09c8b59045449", 0, ["*"], false);

 Next, I was receiving NULL because I did not return the item. Needed to add

return layer

Finally, after returning the item, I was getting weird behavior. It was returning a table that was not associated with the item ID. Like...a totally different table! I tripled checked the item ID and event tired some random ones fro data my organization holds. Still, the wrong table each time. Turned out, you need to add the layer ID after the item ID.  So, I had to change the FeatureSetByPortalItem itemID from 0 to the id of my layer.

 

 I wasn't coming across a lot of documentation explaining how to use Data Expressions. All of the examples showed the FeatureSetByPortalItem, but none of them explained why. Intuitively, I just thought I needed a portal account. In the end, all I wanted to do was reference my organizational data directly, without refering a map or layer first.

View solution in original post

1 Reply
MichaelMacRae
New Contributor II

SO, I figured out where I was going wrong. I am fairly new to Arcade, but have a solid scripting background, so I shouldn't have missed some things.

First, the FeatureSetByPortalItem function does work, regardless whether or not you have ArcGIS Portal. It's just a function call for an item in your given portal. So, the following works:

agol = Portal("https://www.arcgis.com");
layer = FeatureSetByPortalItem(agol, "7b1fb95ab77f40bf8aa09c8b59045449", 0, ["*"], false);

 Next, I was receiving NULL because I did not return the item. Needed to add

return layer

Finally, after returning the item, I was getting weird behavior. It was returning a table that was not associated with the item ID. Like...a totally different table! I tripled checked the item ID and event tired some random ones fro data my organization holds. Still, the wrong table each time. Turned out, you need to add the layer ID after the item ID.  So, I had to change the FeatureSetByPortalItem itemID from 0 to the id of my layer.

 

 I wasn't coming across a lot of documentation explaining how to use Data Expressions. All of the examples showed the FeatureSetByPortalItem, but none of them explained why. Intuitively, I just thought I needed a portal account. In the end, all I wanted to do was reference my organizational data directly, without refering a map or layer first.