Change "Assign_Status" by python script for Workforce

495
2
01-10-2023 06:30 AM
FrederikPicavet
Occasional Contributor

I would like to change the status of all 'assigned' tasks in Workforce to 'Unassigned' , I found the github stript:

project.assignments.search()[0].update(status="Declined",declined_date=datetime.datetime.now(), declined_comment="not doing it")
print("Assignments before Deletion: " + str(len(project.assignments.search())))
project.assignments_item.layers[0].delete_features(where="status=4")
print("Assignments after Deletion: " + str(len(project.assignments.search())))

that I have changed to : 

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

 but I'm new at Python; I don't want to 'delete.features' but adapt, change this (where="status=1") to ....  (where="status=0")

How to to this ? 

Please help

0 Kudos
2 Replies
FrederikPicavet
Occasional Contributor

I was hoping to get some answers from this forum .... 

I would like all tasks in workforce that are assigned or unassigned  to be marked as completed :

# as completed
for assignment in assignments:
        if assignment.status == "unassigned":
            assignment.status = "completed"
        if assignment.status == "assigned":
            assignment.status = "completed"
assignments = project.assignments.batch_update(assignments)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-cdac3234566c> in <module>
      1 # as completed
      2 for assignment in assignments:
----> 3         if assignment.status == "unassigned":
      4             assignment.status = "completed"
      5         if assignment.status == "assigned":

AttributeError: 'Feature' object has no attribute 'status'

 

How to do this ? 

thank you for the help

0 Kudos
RobertAnderson3
MVP Regular Contributor

So I was just trying to do something similar, but I wanted any of my assignments that were assigned but not completed to be declined (I run it on a weekly basis for this task) and I set it up as follows:

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")

Realizing I have it set up two different ways for status, the value and the alias. And seeing the batch_update command you have in there, may be more efficient ways to do it but hey, it seems to work! I get the schema information from here: https://doc.arcgis.com/en/workforce/android-phone/help/workforce-schema.htm

0 Kudos