Announcement

Collapse
No announcement yet.

Obtaining contacts ids of an account

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

  • rabii
    replied
    glad it worked for you

    cheers

    Leave a comment:


  • Athensmusic
    replied

    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

    Leave a comment:


  • rabii
    replied
    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

    Leave a comment:


  • Athensmusic
    replied
    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

    Leave a comment:


  • Maximus
    replied
    Try to use this Formula https://docs.espocrm.com/administrat...indrelatedmany.

    Leave a comment:


  • esendino
    replied
    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:	465
Size:	91.2 KB
ID:	72174

    Leave a comment:


  • Maximus
    replied
    Hi.
    Please try the 'contactsIds' attribute for it.
    Attached Files

    Leave a comment:


  • esendino
    started a topic Obtaining contacts ids of an account

    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
Working...
X