Function FindRelatedMany to find contact histories

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eduardofendrich
    Member
    • Jul 2021
    • 49

    Function FindRelatedMany to find contact histories

    Hi,

    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?

    Thanks
  • eymen-elkum
    Active Community Member
    • Nov 2014
    • 472

    #2
    Hi, Use Note and not stream.

    Code:
    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 of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment


    • eymen-elkum
      eymen-elkum commented
      Editing a comment
      You can write another formula on the Note entity directly, will be better
  • esforim
    Active Community Member
    • Jan 2020
    • 2204

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

    Comment


    • esforim
      esforim 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
Working...