+44 (203) 695-03-80

Add custom service methods for Workflow

You can create a custom service action for workflow. I want to show how this can be done for a Call entity.

Step 1. Add your method to Services.

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

<?php

namespace Espo\Custom\Services;

use \Espo\ORM\Entity;

class Call extends \Espo\Modules\Crm\Services\Call
{
    public function testServiceAction(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"]
    }
}

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. Final

To enable it, go to Administration panel > Clear Cache.