Select to view content in your preferred language

FeaturSetByName formula not working with hosted feature layers

442
4
12-02-2024 10:51 AM
Labels (3)
Strata_ChrisG
Emerging Contributor

Hello,

 

Was wondering if anyone has worked on field calculations (In Arcade Expressions) on hosted feature layers in ArcGIS Pro. I wanted to grab the the field value of a polygon layer that intersects another and transfer that value over into the other layers field. I have used the following formula: 

// load the point featureclass
var points = FeatureSetByName($datastore, "Shelter_Zones", ["*"], true)

// get the points inside the current polygon feature
var points_in_polygon = Contains($feature, points)

// count them and return the number
return Count(points_in_polygon)

 

I was successful in running this feature when they were native layers created in ArcGIS Pro but cannot get it to run with hosted feature layers. I get the following error:

Invalid expression.
Error on line 2.
Table not found Shelter_Zones

 

I read somewhere that is has to do with first parameter after the function FeatureSetByName. I am assuming this is where the formula is referencing the origin point for the data. My guess is that $datastore is saying the values are held in ArcGIS Pro when they are not. I have tried $map with no success either. 

Has anyone else run into this issue and if so how they you guys resolve this?

 

Many thanks in advance for any help!

 

0 Kudos
4 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @Strata_ChrisG ,

You would need to utilize the Portal functions | ArcGIS Arcade | Esri Developer for hosted/feature services. You first get the portal, followed by the item id, and the layer index of the item( the order from which the service was published).

 

0 Kudos
Strata_ChrisG
Emerging Contributor

HI@RPGIS ,

Thanks for pointing me in the right direction! By chance do you know where to find the layer index of the item or "layerid"? I was able to the item id from the url of the layer site but cannot find the layer id? 

 

Also, does this formula work with AGOL hosted feature layers as well or only Portal (Enterprise) items?

 

Many thanks again!

0 Kudos
Strata_ChrisG
Emerging Contributor

I  ran the formula as: 

var p = Portal("https://********.maps.arcgis.com");
var features = FeatureSetByPortalItem(p, "itemid",layerid);

But I get:

Invalid expression.
Error on line 2.
Object not found "layer name"

I was able to get the item id from the layer page in my organizations AGOL page and grabbed the layer id from copying the features path (in the table of contents) in ArcGIS Pro and then opening it in notepad on my desktop.

Thanks again for the help!

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

So the item id is found in the features url and the layer id is simply the number that is found at the end of the url. Most of the time, if it is a single published layer, the item id is 0.