Error accessing Workforce project

459
4
Jump to solution
08-18-2020 08:13 AM
MattStarry
Occasional Contributor

I am trying to access a Workforce project (new version) using the ArcGIS API for Python. I have upgraded ArcGIS Pro to version 2.6, cloned the default environment, and updated the arcgis package to 1.8.2.

Here is my code:

import arcgis

org_url = 'orgurlhere'
un = 'myUn'
pw = 'myPw'
itemId = 'itemid' #Service ItemId

gis = arcgis.gis.GIS(org_url,un,pw)

item = gis.content.get(itemId)
project = arcgis.apps.workforce.Project(item)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I get the following error:

Traceback (most recent call last):
File "C:\myscripts\test_wf.py", line 11, in <module>
project = arcgis.apps.workforce.Project(item)
File "C:\Users\myun\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\arcgis\apps\workforce\project.py", line 45, in __init__
self._assignment_schema = AssignmentSchema(self.assignments_layer)
File "C:\Users\myun\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\arcgis\_impl\common\_utils.py", line 158, in _lazy_property
setattr(self, attr_name, fn(self))
File "C:\Users\myun\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\arcgis\apps\workforce\project.py", line 233, in assignments_layer
return FeatureLayer(self.assignments_layer_url, self.gis)
File "C:\Users\myun\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\arcgis\apps\workforce\project.py", line 183, in assignments_layer_url
return self._item_data['assignments']['url']
KeyError: 'assignments'

I am just starting out with the ArcGIS API for Python but this seems pretty basic. Does anyone have any ideas what might be wrong here?

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

Matt Starry (SWLP)

You need to install the package Workforce package.

To install, use the following link. It also contains sample notebooks.

GitHub - Esri/workforce-scripts: A set of scripts to help administer Workforce projects. 

View solution in original post

4 Replies
MehdiPira1
Esri Contributor

Hi Matt Starry (SWLP)‌,

Can you please explain more about what you are trying to achieve?

0 Kudos
MattStarry
Occasional Contributor

Sure. I am exploring the ArcGIS API for Python. In this test case, I will attempt to update the status and geometry of a single worker (full code not provided).

It is my understanding that I have to get the Workforce item and set the project prior to updating the worker info. So, I am running into an issue right out of the gate.

0 Kudos
MehdiPira1
Esri Contributor

Matt Starry (SWLP)

You need to install the package Workforce package.

To install, use the following link. It also contains sample notebooks.

GitHub - Esri/workforce-scripts: A set of scripts to help administer Workforce projects. 

View solution in original post

MattStarry
Occasional Contributor

After reading that page carefully, I see I have to update the ArcGIS API for Python to version 1.8.3 (pre-release). Once I did that, my script ran as expected with no errors. Thanks for pointing me in the right direction.