I have one more question - "How can I achieve this for a multi-user task". Suppose there are three assignees in a currently active sequential task : "User1", "User2", "User3". Of which, User1 is currently active and I want to remove "User1" and "User2" and add new assignee "User4".
If the user tasks have already been created then it will be the same approach querying for those tasks and updating their assignees. If you are talking about user tasks that haven't been created yet that's something different.
In your example you use the method task.setAssignee("newassignee"); I have the same question, but what I have as input is the "ExternalID" of the user, and am struggling to find a way to get the "userId" to use the setter. Is this possible? I mean, to assign a task to someone with ExternalId="xyz" ? Thank you.