AnsweredAssumed Answered

ValidationError: Model requires an object_id

Question asked by dwebb_BCGISID on Jan 10, 2020
Latest reply on Feb 13, 2020 by dwebb_BCGISID

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!

 


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>")


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

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)

Outcomes