+44 (203) 695-03-80

Adding custom service action for Workflow

Workflow allows to create custom service actions. This example will show how this can be done for a Call entity.

Step 1. Create Service class

Create a file “custom/Espo/Custom/Services/TestService.php” if it doesn’t exist and add a method:

<?php

namespace Espo\Custom\Services;

use \Espo\ORM\Entity;

class TestService extends \Espo\Core\Services\Base
{
    public function testServiceAction($workflowId, Entity $entity, array $additionalParameters = null)
    {
        //your code here
    }
}

Step 2. Define the run service method in metadata

Create/edit the file “custom/Espo/Custom/Resources/metadata/entityDefs/Workflow.json”

{
    "serviceActions": {
        "Call":{
            "testServiceAction": {
                "serviceName": "TestService",
                "methodName": "testServiceAction"
            }
        }
    }
}

Step 3. Add a label

To add a label of the run service method, please add/edit the file “custom/Espo/Custom/Resources/i18n/en_US/Workflow.json”

{
    "serviceActions": {
        "testServiceAction": "Label for TestServiceAction"
    }
}

Or if you have the same method name in several entities, you can add such translations:

{
    "serviceActions": {
        "CallTestServiceAction": "Label for Call TestServiceAction",
        "TaskTestServiceAction": "Label for Task TestServiceAction"
    }
}

Step 4. Enable

To enable it, go to Administration panel > Clear Cache. Now, the service action is available under workflow action.