Obtaining contacts ids of an account

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esendino
    Senior Member
    • May 2019
    • 158

    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
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

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

    Comment

    • esendino
      Senior Member
      • May 2019
      • 158

      #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:	514
Size:	91.2 KB
ID:	72174

      Comment

      • Maximus
        Senior Member
        • Nov 2018
        • 2731

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

        Comment

        • Athensmusic
          Member
          • Feb 2020
          • 51

          #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

          • rabii
            Active Community Member
            • Jun 2016
            • 1250

            #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

            • Athensmusic
              Member
              • Feb 2020
              • 51

              #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

              • rabii
                Active Community Member
                • Jun 2016
                • 1250

                #8
                glad it worked for you

                cheers
                Rabii
                Web Dev

                Comment

                Working...