Skip to main content
September 28, 2021
Question

error in for each with a "average" query

  • September 28, 2021
  • 8 replies
  • 0 views

HI!

So i am trying to get an average rating from my database and insert it in a foreach so i can display the average rate for all the items that are populated using the same foreach. Here is part of the code:

           ),
                  a!forEach(
                    items: local!filtered,
                    expression: 
                    a!localVariables(
                      local!queryrating: rule!AS_Get_Rating(fv!item.id),
                      local!ratestar: local!queryrating.rating_average,
                    a!boxLayout(
                        label: "",

but i get this error: Interface Definition: Expression evaluation error at function a!forEach [line 63]: Error in a!forEach() expression during iteration 2: Expression evaluation error: Invalid index: Cannot index property 'rating_average' of type String into type List of Variant

which is weird because "rating_average" is of type number, any help?

    8 replies

    September 28, 2021

    i think its because in iteration 2 i dont have a rate available on that item, how do I go around that?

    acaciob0002
    September 28, 2021

    Hi [mention:f9aba0930c5d41b98630cf9a39c51b01:e9ed411860ed4f2ba0265705b8793d05]

    Have you tried index?

    tointeger(index(local!queryrating,"rating_average",null))

    Regards,

    Acacio B

    September 29, 2021

    And what does the tointeger does in this example?