Updating task "Assigned to" field to current user when app is launched

I was going to send you down a path of getting the current value of the field, appending your current user to that list, then updating with the full list.

But, as it turns out, the API has a much smarter solution: you can add the multi_entity_update_modes param to your update() call , specifying whether to set, add, or remove.

So, now your code looks like this:

    if self.parent.context.task:
        task_id = self.parent.context.task['id']
        data = {
            'sg_status_list' : 'ip',
            'task_assignees' : [ {
                'type':'HumanUser', 
                'id' : self.parent.context.user['id'] } ]
        }
        self.parent.shotgun.update(
            'Task', 
            task_id, 
            data, 
            multi_entity_update_modes={'task_assignees' : 'add'} )

(The only addition is the multi_entity_update_modes param; I just changed the line wrapping.)

Please send pastries to @Michael.Kessler; he’s the one that told me about this solution :blush:.

6 Likes