Most pressing question:
I'm working with the ArcGIS Python API for Workforce and basing my code off this example.
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.)
Thanks!
## https://github.com/Esri/workforce-scripts/blob/master/notebooks/dev_summit_2019/Step%203%20-%20Add%20Assignments%20From%20Existing%20Layer.ipynb
import arcpy
from datetime import datetime
import pandas as pd
from arcgis.gis import GIS
from arcgis.apps import workforce
param = arcpy.GetParameterAsText(0)
gis = GIS("<agol>", "<user>", "<pw>") ## Credentials for dispatcher
item = gis.content.get("<itemid>")
project = workforce.Project(item) ## https://developers.arcgis.com/python/api-reference/arcgis.apps.workforce.html#project
workerManager = workforce.managers.WorkerManager(project) ## https://developers.arcgis.com/python/api-reference/arcgis.apps.workforce.managers.html#arcgis.apps.workforce.managers.WorkerManager
worker = workerManager.get(user_id="<user>")
layer = gis.content.get("<itemid>").layers[0]
features = layer.query(where="field_name = " + str(param), out_sr=3857).features
## https://developers.arcgis.com/python/api-reference/arcgis.apps.workforce.html#assignment
assignments = []
for feature in features:
assignments.append(
workforce.Assignment(
project=project,
geometry=feature.geometry,
assigned_date=datetime.now(),
location=feature.attributes["location"],
description=feature.attributes["description"],
priority=1,
assignment_type="Update Assignment",
status=1,
worker=worker
)
)
project.assignments.batch_update(assignments)