Compare Webmap Layer to WorkForce Assignment Layer

843
7
09-24-2019 06:32 AM
RobbieEisenrich
New Contributor III

Howdy,

Following the "Automatically generating assignments in Workforce " I was able to get a script working for automating workforce Assignment generation. I would like to add a condition to this to first check for any existing assignments before generating a new one. To do this I would like to compare the ID number(leaknumber) in my webmap layer to the workOrderId in the assignments layer. If the webmap id number does not exist in the workOrderId field then I would like for it to generate a assignment.

Below is the existing input for generating assignments 

I am fairly new to arcgis api for python and am not sure the best way to go about this. Some blogs state to compare layers, I should first join them and then look for differences. I have also @seen others that create a loop within a loop to first check if feature service 1 == feature service 2. 

What is the most efficient way to add this condition in?

Thanks!

Tags (2)
0 Kudos
7 Replies
KristinVernon
New Contributor III

Did you ever figure this out? Currently I'm trying to create a join for an assignment layer in workforce with a Survey123 layer that references my geodatabase. I'm comparing the WorkOrder ID field with a Job Number field in my database and it appears that the join cannot read them as the same thing even though they are the same value and data type.

I need help.

0 Kudos
by Anonymous User
Not applicable

How are you trying to create the joined layer? When you say "layer references my geodatabase" do you mean it's an enterprise geodatabase hosting data through ArcGIS server?

0 Kudos
by Anonymous User
Not applicable

Regarding the OP,

Probably the most efficient way to do this would be to query the assignments layer prior to creating the assignment with a query like "workOrderId = '<your work order id>'. If that returns no features, then you know that assignment hasn't been created yet. If you have a lot of new work orders, it could be faster to query all of the assignments and then iterate over them in Python and check for matching work order ids.

0 Kudos
KristinVernon
New Contributor III

How would you go about querying the hosted assignment layer? I wanted to create a query layer however the assignment layer is hosted on my portal and the layer I want to compare it with is in my geodatabase (to answer your second question, yes it is a SQL Server Database and its feature service is hosted through the ArcGIS server). 

I was trying to find a way to bring my assignment layer from workforce into my geodatabase but I can't seem to find a way to do so.

0 Kudos
by Anonymous User
Not applicable

You'd have to query the assignments layer via the feature service layer Rest API since it's a hosted service. You won't be able to create a query layer since the data is coming from two different sources (hosted feature service, sql server table).

You could write a Python script to query the assignments from the assignments layer and then insert the results into your SQL server tables directly or via it's associated feature service.

0 Kudos
KristinVernon
New Contributor III

Would you mind sharing any links that can show me how to query the REST API and how I'd go about deploying Python scripts to work with the environment? Sorry, this is all relatively new to me but I can already foresee the usefulness of using scripting to automate a number of processes.

0 Kudos
by Anonymous User
Not applicable

The Workforce team provides some example Python scripts here:

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

You can read more about ArcGIS API for Python here:

Guide | ArcGIS for Developers