Camunda external task in php

I have integrate camunda-php-sdk into magento2(php). I am working on the camunda modeler external service task.

enter image description here

I need to retrieve form in external service task (Correction Of Data) and correct the data and again send to approver.

I had tried more than 6 hours but still I am unsuccessful to retrieve form in external task

external task detail (http://localhost:8080/engine-rest/engine/default/external-task/)

[{“activityId”:“correction_of_data”,“activityInstanceId”:“correction_of_data:54f38f5e-a1b1-11e6-b53d-6a39a670a0ae”,“errorMessage”:null,“executionId”:“54f38f5d-a1b1-11e6-b53d-6a39a670a0ae”,“id”:“54f3b66f-a1b1-11e6-b53d-6a39a670a0ae”,“lockExpirationTime”:null,“processDefinitionId”:“gwork_loan_approval:1:ea3f9c04-a1ad-11e6-b53d-6a39a670a0ae”,“processDefinitionKey”:“gwork_loan_approval”,“processInstanceId”:“431e485d-a1b1-11e6-b53d-6a39a670a0ae”,“retries”:null,“suspended”:false,“workerId”:null,“topicName”:“correctionOfData”,“tenantId”:null,“priority”:0}]

I could not found anything related to external task get/set method in camunda-php-sdk so I don’t know how to retrieve form here for correction.

can anyone share your thoughts with some code snippet in php?

Below snippet is retrieving the form field value, please note here I am not using camunda-php-sdk. Write my own code which use REST api of camunda. I think here after I will write my own! :slight_smile: this much as simpler than using php-camunda-sdk.

public function getExternalTask()
{
        try
        {
            $data = array(
                'workerId' => 'aWorkerId',
                'maxTasks' => 2,
                'topics' =>
                    array (
                        0 =>
                            array(
                                'topicName' => 'correctionOfData',
                                'lockDuration' => 10000,
                                'variables' =>
                                    array (
                                        0 => 'Applicant_Name',
                                    ),
                            ),
                    ),
            );
            $data_string = json_encode($data);
            $ch = curl_init('http://192.168.2.45:8080/engine-rest/external-task/fetchAndLock');
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($data_string))
            );

            $result = curl_exec($ch);
            var_dump($result);
        }
        catch (\Exception $e)
        {
            echo $e;
        }

}
1 Like

Hi @busean,

yes, you can always just write your own requests. You could also provide a pull request to php-sdk if you find some missing functionality.

Cheers,
Askar.

@busean why did you go with the external task pattern rather than a rest web service that exposes your php code which you call through the service task?

1 Like

@StephenOTT

I am new to camunda, I am looking for best practice.

I tried like get the form field values and display that values in form correction process in php. after correction I submit external task form like

public function completeExternalTask($tid,$name,$pid)
    {
        try
        {
                $data = array (
                    'workerId' => $this->_customerSession->getCustomerData()->getEmail(),
                    'variables' =>
                        array (
                            'Applicant_Name' =>
                                array ('value' => $name),

                        ),
                );
                $url='http://172.17.0.3:8080/engine-rest/external-task/'.$tid.'/complete';
                $this->restCall($data,'POST',$url);
        }
        catch (\Exception $e)
        {
            echo $e;
        }

    }


public function restCall($data,$method,$url)
    {
        try
        {
                $data_string = json_encode($data);
                $ch = curl_init($url);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type: application/json',
                        'Content-Length: ' . strlen($data_string))
                );

                $result = curl_exec($ch);
                return $result;
        }
        catch (\Exception $e)
        {
            echo $e;
        }

    }    

If it is not enough smart way, can you please add steps to reproduce your statement?