Announcement

Collapse
No announcement yet.

Obtaining contacts ids of an account

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

  • Obtaining contacts ids of an account

    For the relaionshisps among entities you normally have the multiple link field in one entity that relates to the other.

    And you could use it [linkname]Ids to retrieve an array in the BPM with all the Ids of the other entity.

    For example in the contact entity there is a field called accounts and you can use either accountsIds or accountNames to retrieve all the accounts related to a given contact

    But in the entity Account I can´t find the related field contacts.

    How can I get in the BPM the contacts ids related to a given account?

    Thanks in advance

  • #2
    Hi.
    Please try the 'contactsIds' attribute for it.
    Attached Files

    Comment


    • #3
      The problems is that attribute doesn´t exist

      Please check the Entity manager and look at the account field view

      There is no contacts or contactsIds field. Normally they exist for any relaitionship. But not in this case

      Click image for larger version

Name:	account fields.png
Views:	496
Size:	91.2 KB
ID:	72174

      Comment


      • #4
        Try to use this Formula https://docs.espocrm.com/administrat...indrelatedmany.

        Comment


        • #5
          Hi, we need the contactsIds inside the same Account entity.
          There is no contactsIds attribute and if we use "record\findRelatedMany('Account', $accountId, 'contacts', 100);" how we can get the accountId of the same Account?
          If we manualy add the accountId number for testing, everything works as expected.
          Thanks

          Comment


          • #6
            Best way is to use formula for Account, you can try the code below: go entity Manager and select account and chose formula :

            Code:
            // This should return all count of contacts related to the current account
            $contactsCount = record\count('Contact', 'accountIds=', id);
            
            // This should return the ids of the contacts related to the current account
            $contactsIds = record\findRelatedMany('Account', accountId, 'contacts', $contactsCount, 'createdAt', 'desc');
            Hope this helps

            cheers
            Rabii
            Web Dev

            Comment


            • #7

              Thanks for replying. It didn't work, but it helped to figure out.
              What I was looking for was just id. I didn't knew id returns current entity id.
              So the code needed was that simple:
              $contactsIds = record\findRelatedMany('Account', id, 'contacts', 100);
              Thank you

              Comment


              • #8
                glad it worked for you

                cheers
                Rabii
                Web Dev

                Comment

                Working...
                X