Sum array issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Julio
    Junior Member
    • Sep 2024
    • 7

    Sum array issue

    I have my CRM dashboard, where I have two menus. contracts and cases.
    It turns out that I intend to attribute to the hour consumed the value of the sum of all contracts related to that contract.
    as if it were the sum of the matrix of hours consumed in the case.
    I've already tried adding in the entity manager the code: consumedHours =entity\sumRelated('Case', 'caseConsumedHour', 'name==stockHoursContracts'); but it doesn't work.
    I ask for tips on how to do this sum correctly.

    The images bellow will help you to understand the issue.

    Thank you.​
  • lazovic
    Super Moderator
    • Jan 2022
    • 809

    #2
    Hi Julio,

    Please attempt to use the formula script provided below:
    Code:
    consumedHours = entity\sumRelated('cases', 'caseConsumedHour');


    Make sure that caseConsumedHour is the exact field name in the Case entity.

    Also, please note that when you relate a new case to this custom entity, the consumedHours field value will not change. You need to either update the custom entity record manually so that the formula script is triggered (it only works after saving) or use the workflow: https://docs.espocrm.com/administration/workflows
    Last edited by lazovic; 09-17-2024, 10:36 AM.

    Comment

    • Julio
      Junior Member
      • Sep 2024
      • 7

      #3
      The link you provided does not work.
      The idea is that consumedHour updates every action that is made in the cases related to your contract (when changing the caseConsumedHour, when deleting a case, or when adding another case).
      I have the workflows available, if it is possible to automate this, I accept the help.​

      Comment


      • DashingUno
        DashingUno commented
        Editing a comment
        Delete the last dot "." in lozovices link
    • Julio
      Junior Member
      • Sep 2024
      • 7

      #4
      Im using the formula that you provide, and it is working partially.

      I will create a workflow to resolve situations where a case is deleted.
      Do you have a ideia to solve that?

      Comment

      • Julio
        Junior Member
        • Sep 2024
        • 7

        #5
        but it will not be possible to delete the consumed case because there is no workflow for this type of situation, so if there is a need to delete it, the person should just reset the hours in the related case.
        I think the problem has been resolved.
        Thanks​

        Comment

        Working...