No announcement yet.

sumRelated does not sum target entity related records

  • Filter
  • Time
  • Show
Clear All
new posts

  • sumRelated does not sum target entity related records

    I defined many-to-many relation in Oppotunity for my custom entity ProductItem.
    I added new field into Opportunity entity: amoutProductTotal of type Float
    In entity manager I created formula for Opportunity: amoutProductTotal = entity\sumRelated('productItems','amount')

    The function runs, but does not sum related records of the target entity. For each target entity it sums related records of another (always the same) entity.

    It's a bug or am I doing something wrong?


    (I'm on version 5.5.1)

  • #2
    tried to reproduce this bug on the demo, but it works well.
    But don't forget, that formula works before record saved. Try to modify any field to recalculate total
    Job Offers and Requests

    Find Developer
    Find Customer


    • ivanila
      ivanila commented
      Editing a comment
      I tried to recalculate, it works but sums wrong entity. For all target entities the value of amoutProductTotalis is the same. I found the entity which is used in calculation. When I'm changing its values the calculation is adapted accordingly. But somehow the relation is fixed to the one and only entity and not to the current target entity.
      Probably something went wrong in upgrade process . Because another strange things happend with my installation: Product entity records disappeared (when I click on related record I'm getting 404), I'm not able edit previously defined process flow anymore (screens with blank attributes are displayed) but the flows self works ok. I tried clear cache and rebuild but no success ...

  • #3
    Hello Tanya,

    Thank you for your response, I too have been trying to solve this issue for a while. As per your instructions above I have recreated it again and it still returns the same value each time.

    a) image 01 contains the formula,
    b) image 02 shows how it returns the same value,
    c) image 03 shows the product lines that are being looked up/summed.
    d) I've tried adding a filter to no avail (maybe I am doing it wrong).
    e) If I delete all bookings and start again, it calculates the first one correct then duplicates that value for the rest.

    As you can see it locks in a total from the 1st Booking and that becomes the total thereafter. As per your posting in another thread, we tried creating a hook but it didn't seem to work, please advise?

    I am using version 5.4.5.

    Ivanila, I get error 404 when the url is incorrect i.e maybe you created an entity with name "test" so the url will have /#test at the end. If you then rename that to "trial" for example the url searches for /#trial which had previously been /#test. Thats how I experienced error 404, I don't know how to fix it, I merely deleted the entity and started again and it worked.


    Last edited by NonTau; 12-28-2018, 02:41 PM.


    • #4
      I have the same problem described in the first post (but I'm new to Espo).

      I have very simple formula
      zaplaceno = entity\sumRelated('platbies', 'zaplacenoCastka');

      And it not sum related records of the target entity. For each target entity it sums related records of another (always the same) entity.
      entity\countRelated look like its working correctly


      • NonTau
        NonTau commented
        Editing a comment
        I agree with you same issue I am getting entity/CountRelated works fine but entity/sumRelated is returning the same amount only works on the first record.

    • #5
      Hello all,

      Is there anyone who has figured the above out? Maybe I have done something incorrectly? I can't find a programmer who can fix it, please assist. Thanks for your time.



      • #6


        • #7
          Thank you Yuri you are saviour. Will test it and give you some feedback, enjoy your day.

          Kindest regards



          • #8
            So far so good, the change is working, just add Yuri's additions to the SumRelatedType.php file found in the path given with the formula. Will test somemore and update if required. Thanks again Yuri.

            Best regards



            • #9
              After fix it's working correctly, thanks