Get all Contacts id list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frank
    Member
    • Aug 2015
    • 64

    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!
  • yuri
    Member
    • Mar 2014
    • 8697

    #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.
    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

    • Frank
      Member
      • Aug 2015
      • 64

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

      Comment

      • yuri
        Member
        • Mar 2014
        • 8697

        #4
        $this->getEntityManager()->
        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

        • Frank
          Member
          • Aug 2015
          • 64

          #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

          • Frank
            Member
            • Aug 2015
            • 64

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

            Comment

            • yuri
              Member
              • Mar 2014
              • 8697

              #7
              $entity->id
              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

              • Frank
                Member
                • Aug 2015
                • 64

                #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

                • yuri
                  Member
                  • Mar 2014
                  • 8697

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

                  }
                  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

                  • Frank
                    Member
                    • Aug 2015
                    • 64

                    #10
                    Thx! its works!!!

                    Comment

                    Working...