Workforce - Import Assignments from a CSV - Script geometry help

1681
3
Jump to solution
08-18-2020 01:47 PM
DaveSarver1
Emerging Contributor

I'm a novice at best with Python scripting but it's on the top of the list of things for me to figure out so our organization can more fully utilize Workforce.  I've had success running the title script in the Python Command Prompt written like this:

python create_assignments_from_csv.py -csv-file "N:\RDA_exported_assignments.csv" -u <username> -p <password> -org "https://<our org>.maps.arcgis.com" -project-id "<xxxxxxxxxxxxxxxxxxxxxxxxxxxx>" -x-field "xField" -y-field "yField" -assignment-type-field "AssignmentType" -location-field "Location" -description-field "Description" -priority-field "Priority"   -wkid 102100 -log-file "N:\Rapid Damage Assessment\log.txt" -timezone "US/Pacific"

Again, this worked.  However I can't seem to get the same script to work in a Jupyter notebook. The sample notebook geocodes an address to an x,y location which I already have.  My assignments csv does not have addresses, only x,y location in separate columns (exported from the Assignments Point Layer - see sample below) as the points are along river levees and don't necessarily have addresses, and i used the location field in Workforce for the name of the levee that is to be inspected. How do I get the script to recognize my x,y data?  I've tried converting the x,y data into a single column titled SHAPE with formatting like this: {"x": -122.366238, "y": 47.22577965}.  This seemed to work but as the script created the assignments,  there was no symbology for the new assignments - similar to the discussion here: Workforce 'create assignments from csv' script - no assignments symbolized on map 

I'm really hoping to use notebooks rather than Command Prompt scripts so I can document processes and share more easily.

I'm pretty sure I need to change at least the geometry line(s)?

workforce-scripts/2 - Importing Assignments.ipynb at master · Esri/workforce-scripts · GitHub 

Below is a sample of the csv that works with the Command Prompt script. I know I can delete a lot of these fields, and please let me know if I should.

OBJECTIDxFieldyFieldDescriptionStatusNotesPriorityAssignmentTypeWorkOrderIdDueDateWorkerIdGlobalIDLocationDeclinedCommentAssignedDateAssignmentReadInProgressDateCompletedDateDeclinedDatePausedDateDispatcherIdCreationDateCreatorEditDateEditor
5-13621747.35979005.241Puyallup Left: MP3.0 - 6.8unassignedhighLevee Assessment - DriveZone 1e99c5014-0d2a-4a8b-9dab-278c052f703dRiver Road Levee23CE0246-08E7-4E60-B6AC-49D9DFCF7F297/21/2020 11:40dsarver7/21/2020 12:21dsarver

I hope what I wrote makes sense, and thanks for reading this

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

You'll want to change how the geometry is created. In the script this is created from the X,Y, and spatial reference. You can see it here: workforce-scripts/create_assignments_from_csv.py at master · Esri/workforce-scripts · GitHub 

This is un-tested but I think you want to do something like:

geometry =  {
    "x": row["x"],
    "y": row["y],
    "spatialReference": {
        "wkid": 102100
    }
}

View solution in original post

0 Kudos
3 Replies
by Anonymous User
Not applicable

You'll want to change how the geometry is created. In the script this is created from the X,Y, and spatial reference. You can see it here: workforce-scripts/create_assignments_from_csv.py at master · Esri/workforce-scripts · GitHub 

This is un-tested but I think you want to do something like:

geometry =  {
    "x": row["x"],
    "y": row["y],
    "spatialReference": {
        "wkid": 102100
    }
}

0 Kudos
DaveSarver1
Emerging Contributor

That worked!  Thank you Aaron!!!

0 Kudos
ChristianChacon
New Contributor

How did you solve it, Can you copy your code?, I have tried and I do not solve it. Please

0 Kudos