Announcement

Collapse
No announcement yet.

Get all Contacts id list

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

  • Get all Contacts id list

    Hello everybody! Please tell me the way (preferably immediately write example code) by which I can get id list (or id arrray) of all existing records in "Contact" Entity. Thx for help!

  • #2
    Hi

    In service or in controller classes access to EntityManager

    $entiyManager = $this->getEntityManager();

    $contactList = $entityManager()->gerRepository('Contact')->find();

    EspoCRM Documentation. Contribute to espocrm/documentation development by creating an account on GitHub.

    Comment


    • #3
      can i do it in my EntryPoint? or can i do it in my custom view field .js ?

      Comment


      • #4
        $this->getEntityManager()->

        Comment


        • #5
          ok thx its works, i get object with my Contacts ifro, and how i get only id array?
          Last edited by Frank; 11-07-2015, 05:13 PM.

          Comment


          • #6
            variant of ->get('id') does`t work
            Last edited by Frank; 11-07-2015, 05:14 PM.

            Comment


            • #7
              $entity->id

              Comment


              • #8
                I'm sorry, can you say more precisely Juri:

                i have this EntryPoint:

                <?php
                namespace Espo\Custom\EntryPoints;
                class myEp extends \Espo\Core\EntryPoints\Base
                {
                public static $authRequired = false;
                public function run()
                {
                $contactList = $this->getEntityManager()->getRepository('Contact')->find();
                echo var_dump($contactList);
                }
                }

                then i call it, i see next one: object(Espo\ORM\EntityCollection)#67 (4) { ["entityFactory":"Espo\ORM\EntityCollection"rivate]=> object(Espo\ORM\EntityFactory)#44 (2) { ["metadata"rotected]=> object(Espo\ORM\Metadata)#43 (1) { ["data"rotected]=> array(41) { ["Attachment"]=> array(3) { ["fields"]=> array(14) { ["id"]=> array(3) { ["dbType"]=> string(7) "varchar" ["len"]=> int(24) ["type"]=> string(2) "id" } ["name"]=> array(2) { ["type"]=> string(7) "varchar" ["len"]=> int(255) } ["deleted"]=> array(2) { ["type"]=> string(4) "bool" ["default"]=> ... and etc.

                i see this object and it properties,

                but when i try to add $entity->id like this:

                public function run()
                {
                $contactList = $this->getEntityManager()->getRepository('Contact')->find()->id;
                echo $contactList; // or echo $contactList[1]; or echo var_dump($contactList);
                }

                i see null

                where is my error?

                I'm very, very grateful for your help!

                Comment


                • #9
                  $contactList = $this->getEntityManager()->getRepository('Contact')->find();
                  foreach ($contactList as $contact) {

                  }

                  Comment


                  • #10
                    Thx! its works!!!

                    Comment

                    Working...
                    X