Select to view content in your preferred language

arcade field calculation with ArcGIS Online Feature Services

1257
9
12-29-2022 07:27 AM
Labels (3)
by Anonymous User
Not applicable

Is it possible to us an Arcade expression to calculate attributes for an ArcGIS online feature services?

Use case: Field workers in my department use Quick Capture during a road patrol shift to indicate deficiencies in the field. The Deficiencies feature service powers multiple Workforce projects including one for potholes. I run a model to add new potholes to the Workforce Assignments feature service every morning. I would like to use a calculate expression to determine the DueDate (i.e. date that the pothole needs to be filled by). My calculate expression locates the nearest road feature (which has a Road Classification attribute) and then uses minimum maintenance standards to determine when the pothole needs to be filled by (i.e. Road Class 1 = within 5 days).  I've tested my arcade expression on copies of the datasets in a geodatabase on my computer and it works as expected. Can I reference the ArcGIS Online Road feature service in my expression? Both of the feature services (potholes & roads) are hosted on ArcGIS Online. I add them to an ArcGIS Pro project and plug the expression into the Calculate Field tool. The following expressions both throw me an Object not found error. How do I reference the Roads feature service?

 

var Road = FeatureSetByName($datastore, 'Road');
var Road = FeatureSetByName($Map, 'Road');

 

 

0 Kudos
9 Replies
Teresa_Blader
Frequent Contributor

Would it work if you used FeatureSetbyPortalItem? 

Here's the example esri gives:

 

var p = Portal("https://arcgis.com");
var features = FeatureSetByPortalItem(p, "7b1fb95ab77f40bf8aa09c8b59045449", 0);
Count( Intersects( features, $feature ) );

//OR

var features = FeatureSetByPortalItem(Portal('http://arcgis.com'), "service ID", layer number, ['field names to include'], false)

 

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
by Anonymous User
Not applicable

Thank you! I believe that should work but I receive a Portal item not found error and am not 100% sure that I have access to the feature service even though I am able to view the attribute table in ArcGIS Online. SHartholt_0-1672331132001.png

 

0 Kudos
Teresa_Blader
Frequent Contributor

Shoot! Well here's an example I use from my content in our organization, since the portal depends on where you have access! Maybe it shows a bit more of the code if you're in an organization like me. 

var features = OrderBy(FeatureSetByPortalItem(Portal('https://gis-olmsted.maps.arcgis.com/'), '9e0f2d3a64fb403598c8e6d66679dbf7'
, 0,['*'],false),'Year DESC')
return Top(features, 1)

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
by Anonymous User
Not applicable

thanks for the example! Do you know if this only works for Portal items or if it works for ArcGIS Online feature services as well? I shared a copy of my data as a web layer and I still see an error message:

SHartholt_1-1672409341847.png

SHartholt_0-1672409303056.png

 

 

0 Kudos
Teresa_Blader
Frequent Contributor

My example is an agol feature service. Ours is a stand alone arcgis server portal, but not a federated Portal. They are both technically portals, it's a wee confusing that way. Not sure what yours is! 

Anyway, what I do is create an "item" in AGOL and then link it to something on our rest end point. So even though the rest end point is actually a different url, I still use our AGOL portal because technically the item is hosted in AGOL where as the linked content is on our stand alone server. 

Maybe you have a more complicated issue though. I think this is about as far as my help can take you! 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
by Anonymous User
Not applicable

How do you link the item to something on your rest end point? I think I understand everything else that you have described.

0 Kudos
Teresa_Blader
Frequent Contributor

Sure: 

In AGOL, "New Item", Use URL option, copy and paste your service url from the rest end point. Create, give it a name, then use the item ID in the url for that item to call it into your arcade expression. 

Teresa_Blader_0-1672767395286.pngTeresa_Blader_1-1672767416376.png

Teresa_Blader_3-1672767608660.png

Teresa_Blader_2-1672767515466.png

Teresa_Blader_4-1672767773539.png

 

Teresa Blader
Olmsted County GIS Specialist
by Anonymous User
Not applicable

Maybe it's not working for me since I am attempting to execute the Arcade Expression from ArcGIS Pro? I have added the feature services from ArcGIS Online (Quick Capture points & Workforce Assignments) and Portal (Roads) to a Pro project. I created a model to run a few calculations including the one to grab the road classification from the Roads and use it to populate the DueDate field. 

SHartholt_0-1675363599574.png

SHartholt_1-1675363616336.png

 

 

0 Kudos
Teresa_Blader
Frequent Contributor

Oh, not sure if that works starting from Pro. My directions so far have all described ArcGIS Online pop up builder. Sorry, I missed the part about trying to write the expressions in Pro.

ArcGIS Online pop up expressions can be opened in ArcGIS Pro, but not sure if it works as smoothly the other way around. More importantly, I'm not sure if globals like $map or $datastore work in ArcGIS Pro pop up builder. But I'm not the expert on that front. When I opened my expressions in the Pro pop up builder I got the same error as you (I built these in ArcGIS Online and opened the map in Pro). However this works in my AGOL popup just fine. Now, maybe if you write it correctly and publish it to AGOL from Pro it'll still work even though there's an error here... not sure!

Teresa_Blader_0-1675369965747.png

Since both of your features are in ArcGIS Online already, maybe write the popup expression in the ArcGIS Online map, with your pop up built the way you'd like and then reopen it in Pro after that? 

Also, building a connection to the rest end point can be done in ArcGIS Pro by making a server connection as a user in Catalog. You would need your server and database information, but that could be a way to add it to your project as well if you stick with Pro.

Teresa Blader
Olmsted County GIS Specialist
0 Kudos