Adding custom service action for Workflows¶
Workflows allow to create custom service actions. This example will show how this can be done for a Call entity.
Step 1. Create service class¶
<?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¶
Add or edit (if file exists) the file custom/Espo/Custom/Resources/i18n/en_US/Workflow.json
.
{
"serviceActions": {
"testServiceAction": "Label for TestServiceAction"
}
}
{
"serviceActions": {
"CallTestServiceAction": "Label for Call TestServiceAction",
"TaskTestServiceAction": "Label for Task TestServiceAction"
}
}
Step 4. Add usage tips (optional)¶
Add or edit the file custom/Espo/Custom/Resources/i18n/en_US/Workflow.json
.
{
"serviceActionsHelp": {
"testServiceAction": "This is a description of testServiceAction action"
}
}
{
"serviceActionsHelp": {
"CallTestServiceAction": "This is a description of TestServiceAction for Call entity",
"TaskTestServiceAction": "This is a description of TestServiceAction for Task entity"
}
}
Step 5. Clear cache¶
Administration panel > Clear Cache. Now the service action is available for Workflows in the Run Service Action form.