Announcement

Collapse
No announcement yet.

Adding custom service action

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

  • Adding custom service action

    Hi,

    I'm trying to add an additional service action for use within a workflow according to https://www.espocrm.com/documentatio...rvice-actions/.
    As described, I added an additional service class by copying the sample code and put it into ../custom/Espo/Custom/Services/TestService.php:

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

    Next I added the json-File .../Resources/metadata/entityDefs/Workflow.json actually again by simply copying the sample data:

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

    Last, the labdel assignment in .../Resources/i18n/en_US/Workflow.json and .../Resources/i18n/de_DE/Workflow.json:

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

    Unfortunately, nothing happens after restarting or clearing the cache and I'm really a bit lost now.
    I set the logging level to debug, but in the log files are only entries that seem unrelated to my problem, but belong to the automated email sending I've set up also.

    [2018-05-14 13:22:17] Espo.DEBUG: Workflow\ActionManager: Start workflow rule ID [5ae7759a3088f4076]. [] []
    [2018-05-14 13:22:17] Espo.DEBUG: Workflow\Actions: Start [sendEmail] with cid [0] for entity [Quote, 5ae0dd0d3720934c9]. [] []
    [2018-05-14 13:22:17] Espo.DEBUG: Workflow\Actions: End [sendEmail] with cid [0] for entity [Quote, 5ae0dd0d3720934c9]. [] []
    [2018-05-14 13:22:17] Espo.DEBUG: Workflow\ActionManager: End workflow rule ID [5ae7759a3088f4076]. [] []
    [2018-05-14 13:37:15] Espo.DEBUG: Workflow\ActionManager: Start workflow rule ID [5ae7759a3088f4076]. [] []
    [2018-05-14 13:37:15] Espo.DEBUG: Workflow\Actions: Start [sendEmail] with cid [0] for entity [Quote, 5ae0dd0d3720934c9]. [] []
    [2018-05-14 13:37:15] Espo.DEBUG: Workflow\Actions: End [sendEmail] with cid [0] for entity [Quote, 5ae0dd0d3720934c9]. [] []
    [2018-05-14 13:37:15] Espo.DEBUG: Workflow\ActionManager: End workflow rule ID [5ae7759a3088f4076]. [] []

    I guess the service class has been recognized properly as I found in .../data/cache/application/services.php the following section:

    'ReportSending' => '\\Espo\\Modules\\Advanced\\Services\\ReportSending', 'Workflow' => '\\Espo\\Modules\\Advanced\\Services\\Workflow', 'TestService' => '\\Espo\\Custom\\Services\\TestService', ); ?> Is there anything I can check in addition? Thank you very much


  • #2
    Did you add a workflow for Call with action Run Service Action?

    Comment


    • #3
      I try to create a workflow rule for "Call", and then add a "Action": "Run Service Action"



      At this point I would expect to see the new "TestService", right?
      Last edited by md2803; 05-15-2018, 07:45 PM. Reason: P.S. I'm not sure if you can see the screenshot in the post somehow ...

      Comment


      • tanya
        tanya commented
        Editing a comment
        there is no screenshot

    • #4
      Enclosed the screenshot

      Comment


      • #5
        no, you have to see testServiceAction or it's label
        find in data/cache/application/metadata.php serviceActions for Call. Is it in list?

        Comment


        • #6
          No, it is indeed not in the list in the file "metadata.php". I checked the Workflow.json once more in a json syntax checker, but it seems valid.

          Only the label assignment is in the language file:
          ./data/cache/application/languages/cs_CZ.php: 'testServiceAction' => 'Label for TestServiceAction',
          ./data/cache/application/languages/da_DK.php: 'testServiceAction' => 'Label for TestServiceAction',
          ./data/cache/application/languages/de_DE.php: 'testServiceAction' => 'Label for TestServiceAction',
          ./data/cache/application/languages/en_GB.php: 'testServiceAction' => 'Label for TestServiceAction', ...

          Comment


          • #7
            check twice the path and filename and also check whether this file readable.
            After rebuild this data has to be in the cache metadata

            Comment


            • #8
              The path in my file system is "W:\MAMP\htdocs\EspoCRM-5.1.1\custom\Espo\Custom\Resources\metadata\entity Defs", and in this directory are already some other files generated bei EspoCRM itself:

              Verzeichnis von W:\MAMP\htdocs\EspoCRM-5.1.1\custom\Espo\Custom\Resources\metadata\entity Defs

              17.05.2018 18:08 <DIR> .
              17.05.2018 18:08 <DIR> ..
              11.04.2018 21:43 389 Account.json
              04.05.2018 23:07 266 Email.json
              17.05.2018 18:08 181 Workflow.json
              3 Datei(en), 836 Bytes
              2 Verzeichnis(se), 1.800.439.783.424 Bytes frei

              As far as I can see the file path and name is correct, and also all files are readable.

              You mention a rebuild, that sounds more comprehensive than just cleaning a cache. Is there a particular rebuild process? Am I allowed to erase the data in the cache directory to force a regeneration?

              Comment


              • #9
                yeah, the path is correct. And content...
                yes, you can remove metadata.php before clearing the cache.

                Comment


                • #10
                  Hi Tanya, huge fan here! We have the advanced pack in a few clients, but I have a question about those custom services actions. I have this service /custom/Espo/Custom/Services/LeadSync.php that will sync leads with another EspoCRM database. The question is when I run this action in the lead entity, how can I get lead information (email, first name, etc)? There is something like $userid to send as parameter?

                  <?php
                  namespace Espo\Custom\Services;
                  use \Espo\ORM\Entity;
                  class LeadSync extends \Espo\Core\Services\Base
                  {
                  public function LeadSync($workflowId, Entity $entity, $additionalParameters = null)
                  {
                  //here is where I should call the API to insert the lead to another EspoCRMInstance.
                  }
                  }

                  Comment


                  • #11

                    If this $entity is Lead use ApiClient

                    3rd parameter is $entity->toArray(), or use only neaded fields

                    [
                    'emailAddress' => $entity->get('emailAddress'),
                    'firstName' => $entity->get('firstName'),
                    ....
                    ]

                    Comment


                    • #12
                      What colud be the reason not to see newly created service action?
                      I have followed the tutorial on a page https://www.espocrm.com/features/add...-for-workflow/. I have also checked that metadata.php contains my newly created action.

                      Regards, Egi
                      Attached Files

                      Comment


                      • #13
                        Hmm .. i can see that custom service action is only visible on "Meeting", "Call" and "Quote" entity. How can i have my own action on custom entity??

                        ----

                        I have found out the reason. I have not noticed that in json file there was a "Call" entity. Changed tho my entity and now works.

                        ESPOCRM team you should write more complete tutorials with pointed-out segments that should be changed. This tutorials are so low quality ....
                        Last edited by egi.zaberl; 10-23-2018, 02:12 PM. Reason: Found out what was the reason ....

                        Comment

                        Working...
                        X