Complete user task from outside of microflow and task inbox

0
Hello,   I have entity A and when it is created a workflow triggers. In this workflow there is user task that makes user fill out attribute fields of object A and after that there is 2nd user task that makes admin review and accept/deny it.    Currently user needs to go to task inbox, then click on task associated with task and then user task page pops out, user fills out fields, then clicks button which completes user task and it goes to approval user task so that is how it should work.    Now I want to allow users to also fill out those fields in NewEdit page and then save it. This save button should also finish ongoing user task without any additional effor from user (user should not need to go into task inbox etc.) so user task for approval from admin can start.    Is there a way to do it?   I tried adding association from entity A to System.WorkflowUserTask and in microflow I retrieved System.WorkflowUserTask using this association and I confirmed that correct user task is acctually beeing retrieved (I opened user task page with this user task in argument and correct one showed up) but when trying to use activity "Complete user task" I am getting errors.  Is there something else that I sould do?    I am using Mendix version 9.24.11 and Workflow commons 2.5.0
asked
1 answers
1

What error do you get? My approach was the following, which worked good:

 

First retrieve the correct task, which can be done in several ways. You can make an association from your context entity to the System task via the On Created microflow option in the Edit User Task pane in your workflow, and later retrieve the task using this association. Or you can simply do a Database retrieve and  use some XPath constraints to get the right task (e.g. Include the literal task name in your constraint by going to WorkflowUserTaskDefinition/Name). It seems you had no issues with this part.

 

Now that you have the task object available in your microflow, you can use the Complete user task acitivity. But there are 3 stages the task can have regarding the assigned user, which you need to check before you can do this. Else you may get an error. First retrieve the Assigned user from your task, and then:

 

1. Check if Task assigned user is the same user triggering your microflow. ($AssignedUser = $currentUser). If true, simply Complete user task. If the user trying to complete the user task is not the assigned user, you will have an error.

2. Check if Task assigned user is empty. If true, use the workflowCommons sub flow SUB_UserTask_Assignee_Add with current user, and then apply Complete user task.

3. If false (assigned user is not empty, not the current user, so its a different user), remove the current assignee with SUB_UserTask_Assignee_Remove from workflowCommons, and then add your current user as an assignee. After this apply Complete user task.

 

image.png

answered