Most pressing question:
When I use `batch_add` the code works and it adds an assignment.
However, I do not want to add an assignment, I want to update an existing record from "unassigned" to "assigned" so I want to use 'batch_update'. But when I use that I get an error which says, "arcgis.apps.workforce.exceptions.ValidationError: Model requires an object_id"
Does anyone know what that means or how to fix it?
Less pressing question:
For the 'workforce.Assignment' parameters, I get an error saying "arcgis.apps.workforce.exceptions.ValidationError: Assignment cannot have an empty location". But the documentation on Assignment says location is Optional. Does anyone know why it's required? (This only happens when using 'batch_add' since 'batch_update' doesn't work.)
I am actually trying to accomplish the very same thing and i was wondering if you came up with a solution? I looked at the api documentation but it gives very little information. the documentation here refers to using batch methods but nothing specific to what i require either.
Hi Paul, sorry for the late response. I just got back from vacation and have to re-think through what all I was doing.
Since our workflow switched to a different direction, I ended up doing the `batch_add` function and then running through the update process I found here. https://developers.arcgis.com/python/guide/editing-features/#Updating-features
I hope that helps. I have not tried Aaron's solution.
The "ValidationError: Model requires an object_id" error is because you are calling batch_update on new assignment objects that haven't been inserted into the underlying feature layer. You cannot update a feature that doesn't exist.
The recommended approach would be to do this:
worker = project.workers.get(user_id="<user>") assignments = project.assignments.search(where="<query>") for assignment in assignment: assignment.worker = worker assignment.status = "assigned" assignment.assigned_date = datetime.datetime.utcnow() project.assignments.batch_update(assignments)
An example notebook showing how to assign workers is available here
Additionally all of the manager objects can be directly accessed from the project object (e.g. project.assignments will return the AssignmentManager).
For your second question regarding "location". This attribute is required/expected based on the Workforce information model. This is why you get the validation message. The Python API allows you to create an assignment object without specifying the location so that you could set the property at a later time before creating the assignment.
Thanks Aaron! If I get some time I will try this and see how it works. Our workflow for our current project changed up so I had to go a slightly different direction. Since this project is still a work in progress, I may still need to use `batch_update` but I'll have to cross that bridge when I get there.