How to work with User task

Abstract

In this guide I will demonstrate an easiest process design containing User Task and show how to use API endpoints to work with the delegated User Tasks.

 


Creating Process schema


Use ‘Import’ functionality from processmaker.io to submit a new Process scheme into your PMCORE instance.


Simple User Task delegation process BPMN file, put this content into local bpmn file:


<?xml version="1.0" encoding="UTF-8"?>

<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.9.0">

  <bpmn:process id="Process_1" name="Process_1" isExecutable="false">

    <bpmn:startEvent id="Start" name="Start">

      <bpmn:outgoing>SequenceFlow_1tx9cmo</bpmn:outgoing>

    </bpmn:startEvent>

    <bpmn:endEvent id="EndEvent_0z5hpmz" name="End">

      <bpmn:incoming>SequenceFlow_0jzu59a</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:sequenceFlow id="SequenceFlow_0jzu59a" sourceRef="user_task" targetRef="EndEvent_0z5hpmz" />

    <bpmn:sequenceFlow id="SequenceFlow_1tx9cmo" sourceRef="Start" targetRef="user_task" />

    <bpmn:userTask id="user_task" name="User Task" camunda:assignee="cyclic" camunda:candidateUsers="admin">

      <bpmn:incoming>SequenceFlow_1tx9cmo</bpmn:incoming>

      <bpmn:outgoing>SequenceFlow_0jzu59a</bpmn:outgoing>

    </bpmn:userTask>

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">

      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="Start">

        <dc:Bounds x="173" y="102" width="36" height="36" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="179" y="138" width="24" height="13" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="EndEvent_0z5hpmz_di" bpmnElement="EndEvent_0z5hpmz">

        <dc:Bounds x="419" y="102" width="36" height="36" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="427" y="138" width="20" height="13" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNShape>

      <bpmndi:BPMNEdge id="SequenceFlow_0jzu59a_di" bpmnElement="SequenceFlow_0jzu59a">

        <di:waypoint xsi:type="dc:Point" x="362" y="120" />

        <di:waypoint xsi:type="dc:Point" x="419" y="120" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="345.5" y="105" width="90" height="0" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="SequenceFlow_1tx9cmo_di" bpmnElement="SequenceFlow_1tx9cmo">

        <di:waypoint xsi:type="dc:Point" x="209" y="120" />

        <di:waypoint xsi:type="dc:Point" x="262" y="120" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="235.5" y="98.5" width="0" height="13" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="UserTask_1xi77xl_di" bpmnElement="user_task">

        <dc:Bounds x="262" y="80" width="100" height="80" />

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>



Start new process via webhook


curl -v “127.0.0.1:8000/api/v1/processes/Process_1/events/Start/webhook?test=1"


*   Trying 127.0.0.1...

* TCP_NODELAY set

* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)

> GET /api/v1/processes/Process_1/events/Start/webhook?test=1 HTTP/1.1

> Host: 127.0.0.1:8000

> User-Agent: curl/7.54.0

> Accept: */*

>

< HTTP/1.1 200 OK

< Host: 127.0.0.1:8000

< Date: Tue, 14 Nov 2017 09:54:55 +0000

< Connection: close

< X-Powered-By: PHP/7.1.8

< Cache-Control: no-cache

< Content-Type: application/json

< uid: 54fe0971-4840-4e80-a536-059faef26252

< Node: development

< Access-Control-Allow-Origin: *

< Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS

< Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization

< Date: Tue, 14 Nov 2017 09:54:55 GMT

<

* Closing connection 0

{"success":true}                                                                                                                                                          


Retrieve newly created Instance object


The instance would be in RUNNING state, because the process hits User Task and waiting for it to be completed.


curl -v -H"Authorization: Bearer ACCESS_TOKEN” “127.0.0.1:8000/api/v1/processes/Process_1/instances/"


{

    "data": [

        {

            "type": "instance",

            "id": "24ce75d8-83a6-4dab-8f69-38b41169b549",

            "attributes": {

                "process_id": "2b9fe24a-c9bf-4031-9eba-4274c20100d4",

                "duration": null,

                "sent_messages": [],

                "init_user_id": null,

                "data_model": "53eae51e-3b46-4927-b810-d1eb61e54cac",

                "status": "RUNNING",

                "created_at": "2017-11-14T09:54:55+00:00",

                "updated_at": "2017-11-14T09:54:55+00:00"

            }

        }

    ],

    "meta": {

        "pagination": {

            "total": 1,

            "count": 1,

            "per_page": 15,

            "current_page": 1,

            "total_pages": 1,

            "links": []

        }

    }

}


Get a list of delegated tasks


Task Instance would be in DELEGATED state, its waiting for User action.


curl -v -H"Authorization: Bearer ACCESS_TOKEN” “127.0.0.1:8000/api/v1/task_instances/delegated"


{

    "data": [

        {

            "type": "task_instance",

            "id": "6eddc2b9-a967-474e-a7ab-807d84424d7e",

            "attributes": {

                "task_id": "90de84cd-e98a-4e10-919f-aa04944da9bc",

                "instance_id": "24ce75d8-83a6-4dab-8f69-38b41169b549",

                "user_id": "3fe4e9b1-6df2-45e2-a4e2-db896ab5109a",

                "group_id": null,

                "status": "DELEGATED",

                "priority": "1",

                "delegate_date": "2017-11-14T09:54:55+00:00",

                "start_date": null,

                "finish_date": null,

                "task_due_date": null,

                "risk_date": null,

                "data": null,

                "duration": 0,

                "instance_overdue_percentage": null

            }

        }

    ],

    "meta": {

        "pagination": {

            "total": 1,

            "count": 1,

            "per_page": 15,

            "current_page": 1,

            "total_pages": 1,

            "links": []

        }

    }

}


Retrieve Task Instance object


Response would contain Task Instance object as well as Data Model, so you may present some data for a User to made decision based on. This is optional step, just to show a way to get Task Instance object knowing its ID.


curl -v -H"Authorization: Bearer ACCESS_TOKEN” “127.0.0.1:8000/api/v1/task_instances/6eddc2b9-a967-474e-a7ab-807d84424d7e"


{

    "data": {

        "type": "task_instance",

        "id": "6eddc2b9-a967-474e-a7ab-807d84424d7e",

        "attributes": {

            "task_id": "90de84cd-e98a-4e10-919f-aa04944da9bc",

            "instance_id": "24ce75d8-83a6-4dab-8f69-38b41169b549",

            "user_id": "3fe4e9b1-6df2-45e2-a4e2-db896ab5109a",

            "group_id": null,

            "status": "DELEGATED",

            "priority": "1",

            "delegate_date": "2017-11-14T09:54:55+00:00",

            "start_date": null,

            "finish_date": null,

            "task_due_date": null,

            "risk_date": null,

            "data": null,

            "duration": 0,

            "instance_overdue_percentage": null

        },

        "relationships": {

            "data_model": {

                "data": {

                    "type": "data_model",

                    "id": "53eae51e-3b46-4927-b810-d1eb61e54cac"

                }

            }

        }

    },

    "included": [

        {

            "type": "data_model",

            "id": "53eae51e-3b46-4927-b810-d1eb61e54cac",

            "attributes": {

                "dataModel": {

                    "uid": "54fe0971-4840-4e80-a536-059faef26252",

                    "test": "1"

                },

                "instance_id": "24ce75d8-83a6-4dab-8f69-38b41169b549"

            }

        }

    ]

}


Completing Task Instance


Here is the example of changing Task Instance state to COMPLETE. Here you also may pass ‘content’ attribute with additional data which will be added to Data Model. After completing Task Instance the engine will continue processing Process Instance according to its design scheme.


curl -v -H"Content-Type:application/json" -H “Authorization: ACCESS_TOKEN" "127.0.0.1:8000/api/v1/task_instances/6eddc2b9-a967-474e-a7ab-807d84424d7e" -X PATCH --data '{

      "data": {

        "type": "task_instance",

        "attributes": {"status": "COMPLETE"}

      }

    }’

{

    "data": {

        "type": "task_instance",

        "id": "6eddc2b9-a967-474e-a7ab-807d84424d7e",

        "attributes": {

            "task_id": "90de84cd-e98a-4e10-919f-aa04944da9bc",

            "instance_id": "24ce75d8-83a6-4dab-8f69-38b41169b549",

            "user_id": "3fe4e9b1-6df2-45e2-a4e2-db896ab5109a",

            "group_id": null,

            "status": "COMPLETE",

            "priority": "1",

            "delegate_date": "2017-11-14T09:54:55+00:00",

            "start_date": null,

            "finish_date": null,

            "task_due_date": null,

            "risk_date": null,

            "data": null,

            "duration": 0,

            "instance_overdue_percentage": null

        }

    }

}


Retrieving Process Instance after completing User Task 


Process Instance would be in COMPLETED state, since its processed Task Instance and reached its End Event.


curl -v -H"Content-Type:application/json" -H "Authorization: Bearer ACCESS_TOKEN” “127.0.0.1:8000/api/v1/processes/Process_1/instances"


{

    "data": [

        {

            "type": "instance",

            "id": "24ce75d8-83a6-4dab-8f69-38b41169b549",

            "attributes": {

                "process_id": "2b9fe24a-c9bf-4031-9eba-4274c20100d4",

                "duration": null,

                "sent_messages": [],

                "init_user_id": null,

                "data_model": "53eae51e-3b46-4927-b810-d1eb61e54cac",

                "status": "COMPLETED",

                "created_at": "2017-11-14T09:54:55+00:00",

                "updated_at": "2017-11-14T10:21:07+00:00"

            }

        }

    ],

    "meta": {

        "pagination": {

            "total": 1,

            "count": 1,

            "per_page": 15,

            "current_page": 1,

            "total_pages": 1,

            "links": []

        }

    }

}