Announcement

Collapse
No announcement yet.

ORM

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

  • ORM

    Hello Yuri.

    It's insane for me to understand instructions in @development section

    I want to sync some data from my system and create new leads, new calls from my system. But I cant understant how to create even entity object.

    Can you please write code which can
    1. create new lead with specific data (full code with including right namespaces, classes, includes and etc)
    2. update it some leads


  • #2
    Hi

    It's documented quite explicitly. There are a lot of examples in espocrm codebase. Use search in file contents to find what you need.

    1 . Create new entity

    2. Set value

    3. Store entity.

    PHP Code:

    $account 
    $entityManager->getEntity('Account');
    $account->set('name''Test');
    $entityManager->saveEntity($account); 

    Comment


    • #3
      Originally posted by yurikuzn View Post
      Hi

      It's documented quite explicitly. There are a lot of examples in espocrm codebase. Use search in file contents to find what you need.

      1 . Create new entity

      2. Set value

      3. Store entity.

      PHP Code:

      $account 
      $entityManager->getEntity('Account');
      $account->set('name''Test');
      $entityManager->saveEntity($account); 

      You thinkin' that everbody are programmers and know very good OOP)

      There is api/v1/index.php

      require_once('../../bootstrap.php');

      $app = new \Espo\Core\Application();
      $app->run();


      I write next...

      $account = $entityManager->getEntity('Account');
      $account->set('name', 'Test');
      $entityManager->saveEntity($account);

      how to create object $entityManager?
      Last edited by daniil.gorenko; 01-12-2016, 12:21 PM.

      Comment


      • #4
        Rather than try and bootstrap your own mini Espo application, create an EntryPoint and send a GET request to the existing API.

        Like this example class:

        application/Espo/Modules/Crm/EntryPoints/MyCreateEntityEntryPoint.php
        PHP Code:
        <?php
        namespace Espo\Modules\Crm\EntryPoints;

        use 
        \Espo\Core\Exceptions\NotFound;
        use 
        \Espo\Core\Exceptions\Forbidden;
        use 
        \Espo\Core\Exceptions\BadRequest;

        class 
        MyCreateEntityEntryPoint extends \Espo\Core\EntryPoints\Base
        {
          public static 
        $authRequired false;

          public function 
        run()
          {
            
        $type $_GET['entityName'];

            
        $entity $this->getEntityManager()->getEntity($type);
            
        $entity->set('assignedUserId'"system");
            
        $entity->set('teamsIds', array("1"));

            if (
        $type === 'Lead') {
              
        $entity->set('firstName'$_GET['firstName']);
              
        $entity->set('lastName'$_GET['lastName']);
            }

            
        $this->getEntityManager()->saveEntity($entity);
          }

        }

        Then perform a GET request, something like:

        http://espo.myhost.com/?entryPoint=myCreateEntityEntryPoint&entityName=Lead&firstName=John&lastName=Doe

        Comment


        • #5
          aladaircr is right.

          entityManager is available in classes like entry points, record services, repositories, select managers.

          Comment

          Working...
          X