Calling a service method from another service. [ESPO Upgrade 6.1.0 -> 7.0.10]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AgentT
    Member
    • Aug 2021
    • 77

    Calling a service method from another service. [ESPO Upgrade 6.1.0 -> 7.0.10]

    Previously I was doing:
    From Contact service:
    Code:
    $this->getRecordService('ClientDetail')->update($clientDetailEntity->id, $clientDetails);
    to update the ClientDetail.

    But since getRecordService method is deprecated, how do I call the functions from another service? Do I have to import the class and call the method?

    There is no documentation regarding this anywhere.

    telecastg item Any help would be appreciated.
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Hello,

    Try the solution posted here: https://forum.espocrm.com/forum/inst...5922#post75922

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1476

      #3
      Hello,
      my knowledge is old (bad certainly).. now if i understand, you can call anything from anything..
      i have not understand DI ...maybe if i undertand english
      but this work..

      look this : https://github.com/hturkoz/espocrm-h...ae4eb3921823ba
      look full file.. construct..

      $myService = $this->serviceFactory->create('MyService');
      $myService->process( $myData->getRaw() );

      so you can call any service from any other place
      Yuri is incredible
      Last edited by item; 04-13-2022, 08:13 PM.
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      • yuri
        Member
        • Mar 2014
        • 8451

        #4
        Record services are the layer for CRUD operations being made via API. So I wouldn't recommend using them in business logic.

        From the record service:
        PHP Code:
        $anotherRecordService = $this->recordServiceContainer->get($entityType); 
        
        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


        • telecastg
          telecastg commented
          Editing a comment
          I will include a link to this post in my adapting to Espo 7 post, it's nice to have an example of the correct usage of Espo 7 re-designed features.
      Working...