5 Replies Latest reply on Sep 2, 2013 4:35 AM by Frank.Hampshire-Oracle

    InstanceSum on nested relationship


      Hi OPA Experts.


      I have following data model and appropriate relationship created.



        Line Items


        Agreement Terms



      I want to use function InstanceSum on field 'ItemPrice' on Entity 'PartDetails' . I tried below:


      the order total = InstanceSum(the PartDetails, the PartDetails ItemPrice)


      It throws me following error:


      "Relationship not recognized. You may need to use an alias when referring to use this relationship. (OPA-E00178)"


        Is it because of scope?, how to use scope statement for above scenario?. Thanks.

        • 1. Re: InstanceSum on nested relationship

          The rule you have described will work if "the order total" is an attribute on the Line Items entity, which is the parent of the PartsDetails relationship. If you are getting the error message described you should do the following:


          1. check that the relationship text for Line ITems --> PartDetails is "the PartDetails"

          2. check that you have a number or currency attribute with the text "the order total" on the Line Items entity.

          3. If you are rely on an automatically created attribute, you should change the attribute to "the Line Items order total". If you include the text of an entity in an attribute, the automatically created attribute will be placed in the correct entity, and then the InstanceSum statement will be correct for the attribute.




          • 2. Re: InstanceSum on nested relationship

            Hi Frank, It is not working. If I flatten the structure keep 1 entity (line item details) under global, InstanceSum works fine. For nested datamodel relationship, instanceSum not working.

            • 3. Re: InstanceSum on nested relationship



              This is almost certainly becuase the rule is trying to create the attribute "the order total" on the global entity, in this case it cannot sum across all line items, all part details.


              Have a look at my suggestions 2. and 3. make either of those changes and your rule should work.




              • 4. Re: InstanceSum on nested relationship

                Hi Frank, Thanks a lot. It is working now. Can you please share the scenario for "Reasoning across entity instances" ForScope statement. Thanks.

                • 5. Re: InstanceSum on nested relationship

                  Glad to hear you got it working.


                  Due to quirks of our rule parser, you can't sum across a deep relationship structure in one rule using scope operations. However with a few itermediate attributes it becomes pretty simple.


                  To sum all the PartDetails of a quote. I would use the following two rules:


                  the line item's total = instancesum(the PartDetails, the PartDetails ItemPrice)


                  the quote's total = instancesum(the line items, the line item's total)



                  You have to sum the totals across one relationship at a time.