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, $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. Add usage tips (optional)
To add usage tips for your service method, add/edit the file “custom/Espo/Custom/Resources/i18n/en_US/Workflow.json”
{
"serviceActionsHelp": {
"testServiceAction": "This is a description of testServiceAction action"
}
}
Or if you have the same method name in several entities, you can add such translations:
{
"serviceActionsHelp": {
"CallTestServiceAction": "This is a description of TestServiceAction for Call entity",
"TaskTestServiceAction": "This is a description of TestServiceAction for Task entity"
}
}
Step 5. Enable
To enable it, go to Administration panel > Clear Cache. Now, the service action is available under workflow action.