No announcement yet.

Function FindRelatedMany to find contact histories

  • Filter
  • Time
  • Show
Clear All
new posts

  • Function FindRelatedMany to find contact histories


    I'm trying to get the latest contact history entries and convert them to a list field, in order to export them. I saw that I could use record\findRelatedMany function. I'm trying to make it works with findRelatedOne (and after use findRelatedMany), but I'm getting

    My actual code is

    histId = record\findRelatedOne('Contact', id, 'Stream', 'createdAt', 'desc')

    But I'm getting nothing as result (and I've inserted one history just to be sure there was some data in the history).

    I'm not able to find the "Stream" relationship name into Contact relationship screen. Where can I find these "common" relationship names?


  • #2
    Hi, Use Note and not stream.

    lastNoteId = record\findOne(
    'Note', 'createdAt', 'desc',
    'type=', 'Post',
    'parentType=', 'Contact',
    'parentId=', id
    lastNotePost = record\attribute('Note', description, 'post');
    Then run recalculate formula from the contact list screen
    Attached Files
    Last edited by eymen-elkum; 10-26-2021, 09:08 AM.
    CEO & Founder of Eblasoft.
    Professional EspoCRM development & extensions.


    • eymen-elkum
      eymen-elkum commented
      Editing a comment
      You can write another formula on the Note entity directly, will be better

  • #3
    Wow this is fantastic, I used eymen code and it work fine for 1 record (latest), it give the ID for the first formula, and the Post itself for the 2nd formula.

    However when I try to use findRelatedMany instead of findOne I get nothing... so I'm the opposite of you.


    • espcrm
      espcrm commented
      Editing a comment
      Hi eymen, what do you mean? The code you posted in #2 used "findOne" and it work fine for me.

      Can you clarify for the future reader?

    • eymen-elkum
      eymen-elkum commented
      Editing a comment
      Not sure but findRelatedMany will return array, so cannot set to varchar field