I have been attempting to create workforce assignments based on values of an existing feature layer on AGOL.
I followed the workflow described in this blog: https://community.esri.com/t5/arcgis-workforce-blog/automate-workforce-with-arcgis-api-for-python/ba...
The section of code where assignments are supposed to be created is:
assignments = []
for feature in pr:
assignments.append(
workforce.Assignment(
project,
geometry=feature.geometry,
location=feature.attributes["locdesc"],
description=feature.attributes["details"],
assignment_type="Inspect Trees",
status="unassigned"
)
)
project.assignments.batch_add(assignments)
In the code from shown above I changed assignment_type="Inspect Trees"] to assignment_type=feature.attributes["AssignType"] in hopes I could take values from my existing feature layer that are stored in the AssignType field and create assignments based on those. I made sure the assignment types matched exactly to what are stored in my feature layer (example 1=Abandoned Car in both the workforce layer and my feature layer).
However, when I try to run the block of code I get the following error:
ValidationError Traceback (most recent call last)
/tmp/ipykernel_28/1267473057.py in <cell line: 2>()
2 for feature in pr:
3 assignments.append(
----> 4 workforce.Assignment( 5 project,
6 geometry=feature.geometry,
/opt/conda/lib/python3.9/site-packages/arcgis/apps/workforce/assignment.py in __init__(self, project, feature, geometry, assignment_type, assigned_date, assignment_read, completed_date, declined_comment, declined_date, description, dispatcher, due_date, in_progress_date, location, notes, paused_date, priority, status, work_order_id, worker)
188 self.status = status
189 self.work_order_id = work_order_id
--> 190 self.assignment_type = assignment_type
191 self.dispatcher = dispatcher
192 self.worker = worker
/opt/conda/lib/python3.9/site-packages/arcgis/apps/workforce/assignment.py in assignment_type(self, value)
380 self._assignment_type = self.project._cached_assignment_types[value]
381 else:
--> 382 raise ValidationError("Invalid Assignment Type", self)
383 elif isinstance(value, str):
384 for at in self.project._cached_assignment_types.values():
ValidationError: Invalid Assignment Type
When I hard code it assignments are created without any issue but instead of creating assignments based on what value is stored in my feature classes, I get assignments that are all the same.
Any insight would be greatly appreciated.