Select to view content in your preferred language

Workforce Assignment Where Clauses, Delete Assignments Older Than a Month

440
3
02-15-2023 06:14 AM
RobertAnderson3
MVP Regular Contributor

I've been working with the ArcGIS Online hosted Notebooks to create and modify assignments in Workforce. I've managed to get it to do a fair bit of what I'd like but the one spot I seem to keep struggling is the syntax for the where clauses when I want to use a field other than "status" as the sample notebooks have it.

Of particular interest would be working with the assigned worker (workerid) and then the date fields. I just can't seem to figure these ones out.

The date clause would be super useful to set up a way to delete assignments that are older than a month.

Any help would be appreciated!

Tags (1)
0 Kudos
3 Replies
by Anonymous User
Not applicable

What do your queries look like?

generally, it will be something like:

 

"Field = 'string'" #<- if the field is a string
"Field = int" #<- if field is a int or float

"<field> conditional value"

 

more examples here

0 Kudos
RobertAnderson3
MVP Regular Contributor
assignments = project.assignments.search(where="status=1")
for features in assignments:
    project.assignments.search(where="status=1")[0].update(status="Declined",declined_date=datetime.datetime.now(), declined_comment="Weekly Timeout of Assignment")
    print(features)

print("Assignments before Deletion: " + str(len(project.assignments.search())))
project.assignments_item.layers[0].delete_features(where="status=1")
print("Assignments after Deletion: " + str(len(project.assignments.search())))

 

This is what I've been working with so far, the loop is being used to update the assignments where the status is assigned, turning them to declined when it runs (weekly, because they're recurring).

The delete portion is what was provided by a sample notebook from Esri. It works well to delete any assignments that were only set as assigned, and I was using this before setting up that loop to decline them.

0 Kudos
by Anonymous User
Not applicable

It looks like it's mixing field types, if status is 1 (int), but then it is setting to a string 'Declined'? is that field set with a domain?

The loop is a little odd too, since you get a list of features that match the query and then for each one redo the search to grab the first one returned. Why not query once and iterate the results:

assignments = project.assignments.search(where="status=1")
for feature in assignments:
    feature.update(status="Declined",declined_date=datetime.datetime.now(), declined_comment="Weekly Timeout of Assignment")
    print(feature)

 
If you wanted to use another field:

assignments = project.assignments.search(where="fieldname=1234")
for feature in assignments:
    feature.update(status="Declined",declined_date=datetime.datetime.now(), declined_comment="Weekly Timeout of Assignment")
    print(feature)

 

Doing the last month filter is a little tricky because on the first of each month would mean the items older than a day. If you run this daily, the first day of the month change over will remove everything in the previous month.  Maybe go by a 30 day block?  Items older than 30 days will be removed?

0 Kudos