workflow service action parameters, and how to find error message.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick
    Member
    • Sep 2016
    • 46

    workflow service action parameters, and how to find error message.

    according to : https://www.espocrm.com/features/add...-for-workflow/

    We can add service action to a workflow.

    My Question is the parameters of the function:

    Code:
    <?php
    
    namespace Espo\Custom\Services;
    
    use \Espo\ORM\Entity;
    
    class TestService extends \Espo\Core\Services\Base
    {
        public function testServiceAction($workflowId, Entity $entity, array $additionalParameters = null)
        {
            //your code here
        }
    }

    what is $entity?

    when I try to print_r on $entity, it gives me 'server 500'


    How to debug Service Action, where to find its errors?
  • yuri
    Member
    • Mar 2014
    • 8528

    #2
    Entity is the target object workflow is applied to. In example it's a Call. Error 500 is normal when printing such objects.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • Patrick
      Member
      • Sep 2016
      • 46

      #3
      Thank you for your reply, You have done a great work for EspoCRM by the way.


      I have a customer entity, derived from Base, with two fields, 'name' and 'ticket'. The ticket is obtained from a remote server base on the name value. I wish to update the ticket value whenever the name is changed.

      My Problem is:

      I fall into a dead-loop, as I cannot do 'save' entity, in 'after-save' trigger.
      I can add if named 'changed' condition, it works for existing record, but it still dead-loop for 'newly created' record.

      This might be suited to read-only field that calculated by formula, any guide on define custom function in formula?
      Last edited by Patrick; 07-05-2017, 04:41 AM.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8528

        #4
        Hi Patrick,

        Could you attach a screenshot of your workflow detail view? Maybe you are changing the name field in workflow that triggers on thie name field change?
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • Patrick
          Member
          • Sep 2016
          • 46

          #5
          Hi Yuri,

          attached is screenshot..




          Code:
                      //Service Action function body
          
                       $entityManager = $this->getEntityManager();
          
                       $name = $entity->get("name");
          
                       //...
                       //get ticket by 'name' using php-curl
                       .....
          
                       $entity->set("ticket", $ticketValue);
          
                       $entityManager->saveEntity($entity); //

          Comment

          • yuri
            Member
            • Mar 2014
            • 8528

            #6

            $entityManager->saveEntity($entity, array('skipWorkflow' => true));
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            • Patrick
              Member
              • Sep 2016
              • 46

              #7
              Great, problem solved.

              Comment

              • Patrick
                Member
                • Sep 2016
                • 46

                #8
                Any method to create attachment inside Service Action routine?


                I stuck at : $this->getFileStorageManager()->putContents

                ( $this is \Espo\Core\Templates\Services\Base )



                Code:
                        
                
                        $attachment = $this->getEntityManager()->getEntity('Attachment');
                        $attachment->set("name", $filename);
                        $attachment->set("type", $mime);
                        $attachment->set("size", $size);
                        $attachment->set("role", "Attachment");
                        $this->getEntityManager()->saveEntity($attachment);
                
                   --------------------
                          |
                          |
                
                        ///this statement cause error when trying to create attachment content in Service Action routine.
                        $this->getFileStorageManager()->putContents($attachment, $contents);
                
                        return $attachment->id;
                    }
                I end up with a lots of empty 'attachment id' which has no content at all.

                Comment

                • Patrick
                  Member
                  • Sep 2016
                  • 46

                  #9
                  I solved it by adding the following code at the begining of Service Action Class.

                  Code:
                      protected function init()
                      {
                          parent::init();
                          $this->addDependencyList([
                              'container',
                              'preferences',
                              'fileManager',
                              'crypt',
                              'serviceFactory',
                              'fileStorageManager'
                          ]);
                      }
                  
                      protected function getFileStorageManager()
                      {
                          return $this->getInjection('fileStorageManager');
                      }

                  Comment

                  Working...