Workforce - Import Assignments from a CSV - AttributeError

569
3
Jump to solution
08-16-2022 01:01 PM
ejuser
by
New Contributor III
I'm using Jupyter Notebook in ArcGIS Pro 2.9.3. I am attempting to create assignments in Workforce using a CSV file.

I have used the code samples provided online related to this topic and cannot get mine to work. I apologize in advance for posting the table and code as images. The formatting was off when attempting to place in the body.

I tried commenting out the line generating the error and another line would be the cause.

 
xFieldyFieldTypeLocationDispatcherDescriptionPriorityWorkOrderIdDueDateAttachmentWorker
-57.830643.31751Quality InspectionNBRTMcNone55553003######## PK
-59.650542.64011Quality InspectionNBRTGNone65521560######## PK
-59.565342.6353Quality InspectionNBRTGNone65521740######## PK
 

 

 

df = pd.read_csv("Workforce_July_Inspects.csv")
vu_assignments = []
for index, row in df.iterrows():
    geometry = {"x" : row['xField'], "y" : row['yField'], "spatialReference" : {"wkid" : 4326}},
    vu_assignments.append(
        workforce.Assignment(
            project,
            geometry=geometry,
            location=row['Location'],
            description=row['Description'],
            priority=row['Priority'],
            work_order_id=row['WorkOrderId'],
            #assigned_date=datetime.now(),
            due_date=row['DueDate'],
            worker=row['Worker'],
            dispatcher=row['Dispatcher'],
            assignment_type='Quality Inspection'
            #assignment_type=row['Type']
            #status="assigned"
        )
    )
project.assignments.batch_add(assignments)

 

 



The error I got was:

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last) In [42]: Line 17: assignment_type='Quality Inspection' File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\assignment.py, in __init__: Line 182: self.due_date = due_date File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\assignment.py, in due_date: Line 467: self._set_datetime_attr(self._schema.due_date, value) File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\feature_model.py, in _set_datetime_attr: Line 111: timestamp = to_arcgis_date(value) if value is not None else None File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\utils.py, in to_arcgis_date: Line 23: return datetime_obj.timestamp() * 1000 AttributeError: 'str' object has no attribute 'timestamp' ---------------------------------------------------------------------------

 

 

 

0 Kudos
1 Solution

Accepted Solutions
graeme_hill
New Contributor III

I don't think you are correctly defining the geometry point object. Check out this guide Part 2 - Working with Geometries | ArcGIS API for Python You are looking at the first example for creating a point, it might look something like this

from arcgis.geometry import Point
for index, row in df.iterrows():
    geometry = Point({"x" : row['xField'], "y" : row['yField'], "spatialReference" : {"wkid" : 4326}})
    

 

Cheers, Graeme

View solution in original post

3 Replies
graeme_hill
New Contributor III

Hi ejuser,

It looks like the issue is with the due date, it is passing as a string but the api is expecting a python datetime object. Have a look at strptime() to convert the csv due date column to a datetime object, strptime requires the formatting of the date time string in your csv but it's showing as ###### in the image. Timezone might be another issue for you to think about.

Cheers, Graeme

Cheers, Graeme
ejuser
by
New Contributor III

Hi Graeme,

Thanks for your response. It has allowed me to get past the error. The rows from the csv have been successfully added to the table, although they do not appear as points on the map. When I select a row from the table, the Zoom to Selection option does not result in any map action.  

 

for index, row in df.iterrows():
    geometry = {"x" : row['xField'], "y" : row['yField']}
geometry

 

 

{'x': -62.764349, 'y': 46.728903}

 

This is the format I am passing to workforce which seems to be the same as when I tried a geocoded address.

0 Kudos
graeme_hill
New Contributor III

I don't think you are correctly defining the geometry point object. Check out this guide Part 2 - Working with Geometries | ArcGIS API for Python You are looking at the first example for creating a point, it might look something like this

from arcgis.geometry import Point
for index, row in df.iterrows():
    geometry = Point({"x" : row['xField'], "y" : row['yField'], "spatialReference" : {"wkid" : 4326}})
    

 

Cheers, Graeme