Upload csv to workforce as assignments

5330
13
10-18-2016 12:21 PM
RaulLeos
New Contributor II

Good day Craig, I currently working on a project that I am trying to implement workforce and I found on that there is a script to help on loading any existing assignments but what I would like to know since I have very little knowledge on python. Is there any tutorials how to run this assignment scripting for workforce.

Tags (2)
0 Kudos
13 Replies
Ystad1
by
New Contributor II

I thought I would make an attempt to answer your question. A few days ago I was in a similiar situation, we are trying to put together a Workforce project for a maintenance department. While Workforce is easy to get started with and create a project it quickly becomes more complicated if you want to do anything more that create assignments by clicking on the screen. I have used Python for various tasks before but would class myself as a beginner and when I have used it for geoprocessing tasks I have always written the code and then run it directly from the GUI (rather than the command line).

While the documentation is good for the Workforce scripts I get the impression it is aimed at people who are already exprienced in Python. 

I'll try to explain the steps I took to import assignments from a csv file, anyone with more experience or that spots a mistake feel free to comment!

1. Follow the instructions here: 

GitHub - Esri/workforce-scripts: A set of scripts to help administer Workforce projects. 

to download and install both Python and ArcREST. I installed using pip, if you haven't got this far then there is information available on the internet about how to download and install pip and python librarys using pip. 

2. Download the zip file including the Worforce scripts and unzip it somewhere on your computer

3. Create a Workforce project here: Workforce for ArcGIS. Add the names of the assignments you wish to include (Assignment Types) in you project and the mobile workers and dispatchers.

4.Open an empty text file and copy the example usage command line propmt to the text file from here.

workforce-scripts/create_assignments_from_csv_readme.md at master · Esri/workforce-scripts · GitHub 

5. In your text file change username and password to your ArcGIS Online username and password. Change 

"https://<org>.maps.arcgis.com" to your ArcGIS online account address. Change the code under -pid to your Workforce project code (you can find it in the web address when you are logged in to your Workforce project).

6. Depending upon how you have installed python and where you have unzipped the workforce scripts you may need to change the paths of the "create_assignments_from_csv.py" script, the assingment.csv file and the log text file. If you add the full file path then python should be able to find them. I have used the arcrest_scripts rather than the standalone_scripts.

7. Open your command line and type "python" without the quotes. If you see some white text and a >>> then you don't need to do anything, if you get an error then python is probably not in your system path. At the start of you text file, replace "python" with the full path to your python.exe (most likely something like C:\Python27\python.exe).

8. If you are going to run the sample assignments.csv then it should work now to copy the command line you have edited in your text file to the command line of your computer. I suggest you try this first before creating your own assignments.

9. When creating own assignments I have followed the structure of the sample csv file with regards to column names and order. If you want to change them then you need to change them in your command line aswell. Depending on your region, if you create a csv from Excel it might use a semi-colon instead of a comma as a seperator.  This casues the python scipt to fail. In the csv file under the column "Type" there must be an interger, the number that you give the assignment here will be assigned an Assignment Type based on the order of the assignment types that you created in the Workforce project earlier. Change "102100" under -wkid to the EPSG code of the coordinate system you are using. If your Due Date format doesn't match "%m/%d/%Y" then you need to add -dateFormat with your date format to the command line. For example -dateFormat "%Y-%m-%d". Attachments work from a file, I haven't got them to work with a web url. 

Hope this helps!

 



RobertMarros
Occasional Contributor II

Hey William,

I followed these instructions and it worked really well so thanks for typing them up for the larger audience. One thing I noticed, and this is more of a use case decision, but if you run the script more than once it will just duplicate the assignments inside of Workforce. I suppose there could be a separate script to filter assignments by date and then you could run the "Create Assignments from CSV File" after that. Just thinking of automation possibilities.  

Also, it seems like at this moment we are stuck with using an integer for type which would require the data entry person to know which number belongs to which assignment type although there might some solutions in Excel to make data entry easier but not sure how they would work on a CSV file  ? Is this what you have experienced? 

Thanks again, Jason

0 Kudos
JonathanGroves
New Contributor III

Hi.

You do indeed need to know the correct integer for Type - I figured these out for my project by making a test project (which only had me as both Dispatcher and Worker), assign a bunch of assignments to myself with incrementing type numbers, quoting these numbers in the Description. Run the export_assignments_to_csv script and print the results out. I also did the same for Priority and workerId...

Hope this helps.

JG

0 Kudos
CraigGillgrass
Esri Regular Contributor

You can also use the Schema documentation; Workforce schema—Workforce for ArcGIS | ArcGIS  for viewing the integer values for Type and other fields that use coded value domains.

Craig

0 Kudos
JonathanGroves
New Contributor III

Great write-up - only feedback is that the syntax for the Python bits differ on Linux, of course.

Also - I would strongly advise setting up a burner project to play with and make sure to master uploading, deleting and downloading assignments before moving to production.

I have a set of (bash, in my case) scripts which call the relevant API script with different parameters depending on what I want. Building a library of these is time very well spent!

Hope this helps.

JG

0 Kudos
AprilChipman
Occasional Contributor III

I'm trying to follow along with these steps and all of the different websites or different instructions on what to use and how. It is all very, very confusing.

One thing keeps coming up, though... The various sites keep saying "...type the following command in your terminal."

What is a terminal and where do I get one? I've downloaded and installed Jupyter and

Anaconda. And used ArcGIS Pro to install the Python API. What am I missing?

0 Kudos
JonathanGroves
New Contributor III

Hi there.

"terminal" in the case of Windows means "Command Prompt" (I'm guessing you're using Windows because you mentioned Anaconda - which I know is a Windows Python distribution).

How to access it depends on your precise Windows version, but these steps will probably work:

1. Click Start

2. Type 'command prompt' (without the quotes)

3. Click the Command Prompt icon which appears.

Note that, for certain operations, you may need to access the Command Prompt as Administrator. In this case, replace step 3 above with:

3. Right-click the Command Prompt icon which appears and choose 'Run as Administrator', then click 'Yes'.

In certain cases you may be offered a 'Command Prompt as Admin' icon - in which case you can click this instead

Hope this helps!

Jonathan

0 Kudos
JayHodny
Occasional Contributor III

Hi William et al.,

I have started working with Workforce including using the scripts available at GitHub, and I am a new to all of this.  In working with a Workforce 'create assignment' script for the Citizen Problem Reporter/Manager solutions, I was pointed to a way to find the assignment type integer values, by Esri staff.  This process uses ArcGIS Pro and the ArcGIS Solutions Deployment tool in the Share tab of Pro's main menu ribbon (this assumes the tool is already installed). 

1) Once the assignment types are created, either directly in the Workforce Add Assignment dialogue screen or through the 'create assignment type' script, go to the 'assignment' service layer in that Workforce project group in ArcGIS Online, and copy the service URL.

2) In Pro, use the Add Data...Data from Path, paste the URL, to pull the service into your Pro project map.  In the Share tab, fire up the deployment tool, and skip to step 3, Modify Domains.  Choose the Assignments layer and Assignment Type field.  This will list the newly created domain codes (the integer values) along with the assignment type descriptions.  In the case of the Citizen Problem Reporter app, there are eight Problem Report feature services (Animal, Blight, Road, Snow/Ice, etc.).  I was advised by Esri staff to create assignment types based on the domain values for each of the eight major problems.  Thus, I had 74 assignment types.  For example, "Road - Pothole," was how I created/named an assignment type. 

3) If closed, open the Solutions deployment tool again in Pro, and input your feature service.  In this example, I used the Road Problems as the input layer and Type of Problem as the field.  I then updated the codes and descriptions based on the assignment type service integer values and descriptions for the 11 Road Problems (coded value domain).  I repeated this process for the other seven major problem report services.  Now when I run the Workforce Reporter create assignment script, the assignment type descriptions are passed to Workforce and the assignment "buttons" are labeled accordingly, see screen shot.  I hope this helps!  Regards, Jay

0 Kudos
AndyBlackman2
New Contributor II

Hi Jay,

I've tried using your method above to find the coded values, along with trying to use the description in my csv for the assignment type. When I run the python script, I get the error 'Invalid Assignment Type' no matter what is in there. I have also tried leaving it blank and no luck. Has anyone else had this issue?

Craig Gillgrass - Please can you help?


Thanks

Andy

0 Kudos