Formula in the Opportunity entity to retrieve values from related Opportunity Items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laimonas
    Senior Member
    • May 2021
    • 197

    Formula in the Opportunity entity to retrieve values from related Opportunity Items

    Hello,

    I am trying to use a formula in the Opportunity entity to retrieve values from related Opportunity Items. I need to manipulate data based on the values stored in the Opportunity Items, but I am not sure how to access these values within the Opportunity entity formula.

    Could someone guide me on how to achieve this?

    Thank you!
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    the opportunity can access related opportunity items through a relationship link items (you just need to loop through items) and get information you need. this should be very easy.
    Rabii
    Web Dev

    Comment

    • macistda
      Member
      • Jul 2022
      • 76

      #3
      entity\sumRelated should do it for numbers etc. Returns a float.



      If you have to loop like rabii wrote
      https://docs.espocrm.com/administrat...general/#while and https://docs.espocrm.com/administration/formula/#while

      Comment

      • Laimonas
        Senior Member
        • May 2021
        • 197

        #4
        Thanks, guys. The loop looks simple, but I was wondering how to manipulate a Json Array? I guess the best solution here is first to retrieve Opportunity Item IDs using this formula:

        $oppItemIdList = record\findRelatedMany('Opportunity', id, 'items', 50, 'createdAt', 'desc');

        And then loop through each item, right?

        Comment


        • rabii
          rabii commented
          Editing a comment
          yes but if you just need the is you can still loop through the items as it will be a list of all ids of related items
      Working...