Announcement

Collapse
No announcement yet.

Create a custom workflow action

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create a custom workflow action

    I need to create a custom action when an email is recieved to the CRM.

    I have crated a workflow for it but I need to set an Action. I see the default actions, but, as mentioned, I need a custom opne to add integration with another platform.

    I have created a php file `TestService.php` (for testing purpose) in the `custom/Espo/Custom/Services` directory.
    Here is the bare-bones code:

    ```
    <?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
    }
    }​
    ```

    I also created `Workflow.json` in the `custom/Espo/Custom/Resources/metadata/entityDefs` directory.
    like so:
    ```
    {
    "serviceActions": {
    "Call":{
    "testServiceAction": {
    "serviceName": "TestService",
    "methodName": "testServiceAction"
    }
    }
    }
    }​
    ```

    i also added a translation for en_US
    ```
    {
    "serviceActions": {
    "testServiceAction": "Label for TestServiceAction"
    }
    }​
    ```

    After cleaning the cache, i went to admin panel > workflow > my created workflow.
    I go to action section, click the + button and i dont see my created action.
    even when selecting `run service action`, the dropdown list is empty

    Click image for larger version

Name:	image.png
Views:	233
Size:	32.2 KB
ID:	106682

    I folowed this tutorial: https://www.espocrm.com/features/add...-for-workflow/
    I also tried by this tutorial: https://docs.espocrm.com/development...rvice-actions/

    But both did not work. what am i missing?​

  • #2
    Hi, seems like you defined the action only for the call entity but you are trying to target Email in your screenshot.

    just change the Entity to Email in the workflow.json

    Comment


    • #3
      Thank you, It seems it worked now.
      Thx for your time.

      If you dont mind, could you point me to the right direcvtion (either hinting me or dropping a good docs link) how i should integrate the method?
      I have this rn:

      ```
      public function testServiceAction($workflowId, Entity $entity, $additionalParameters = null)
      {
      //your code here
      }​
      ```

      the logic is empty. from this way i will need to get the email ID (to get the email data such as attahcment, subject, sender etc).
      Is the `workflowId` the email id?

      its my first time using espocrm and i am so long with it

      Comment

      Working...
      X