possibility to show sum of related entity records in another entity field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nishan Perera
    Active Community Member
    • Jan 2019
    • 348

    possibility to show sum of related entity records in another entity field

    Hi,

    Is there any possibility to show sum of related entity records in another entity field ?


    eg:

    Entities - Gifts & Opportunities
    Fields in gifts - total gifts value
    Fields in opportunities - gift amount


    Simply I want to show the total sum from the opportunities gift amounts in Gifts total gifts value field.

    I have created below sum related under gifts


    totalGiftsValue = entity\sumRelated('opportunities', 'giftAmount');


    Bu the record update as 0.

    Please correct me or help me if I do anything wrongly.
    Cheers!
    Nishan.
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #2
    Hi,
    the formula looks good.
    1. Check an EspoCRM log file for possible error description;
    2. Make sure that the 'giftAmount' field does not equal to '0'.

    Comment

    • Nishan Perera
      Active Community Member
      • Jan 2019
      • 348

      #3
      Hi max,

      Thanks for your reply. I tried and no error found. Isn't this working with Relationships ?? Im trying with relationship. Any idea.
      Cheers!
      Nishan.

      Comment

      • Maximus
        Senior Member
        • Nov 2018
        • 2731

        #4
        It should work with a relationship. Can you provide a screenshot of your Gifts & Opportunities settings?
        Last edited by Maximus; 05-14-2020, 07:30 AM.

        Comment

        • Nishan Perera
          Active Community Member
          • Jan 2019
          • 348

          #5
          Hi Max,

          This is the one I tried in demo site. please check let me know if I did wrongly.
          Cheers!
          Nishan.

          Comment

          • Nishan Perera
            Active Community Member
            • Jan 2019
            • 348

            #6
            Maximus I change the formula as this
            Code:
            totalGiftsValue = entity\sumRelated('opportunity', 'opportunity.giftAmount');
            and I got value is 0

            Cheers!
            Nishan.

            Comment

            • Maximus
              Senior Member
              • Nov 2018
              • 2731

              #7
              I've investigated your screenshots and on my mind totalGiftsValue = entity\sumRelated('opportunities', 'giftAmount'); is the correct formula. Set it for the Gifts entity and recalculate formula for the 'test 1' record. Also, check please whether the 'totalGiftsValue' and 'giftAmount' are proper key values.

              Comment

              • Nishan Perera
                Active Community Member
                • Jan 2019
                • 348

                #8
                Hi Maximus I got it work. I did my mistake in the link that i have to gave. I put entity name instead of link name. This works with the below.


                totalGiftsValue = entity\sumRelated('opportunities', 'opportunity.giftAmount');



                Thanks for the support max.
                Cheers!
                Nishan.

                Comment

                Working...