Skip to main content
Known Participant
Sep 28, 2021 10:59 PM UTC
Question

error in for each with a "average" query

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

    Known Participant
    Sep 28, 2021 11:02 PM UTC

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

    acaciob0002
    Participating Frequently
    Sep 28, 2021 11:23 PM UTC

    Hi [mention:f9aba0930c5d41b98630cf9a39c51b01:e9ed411860ed4f2ba0265705b8793d05]

    Have you tried index?

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

    Regards,

    Acacio B

    Known Participant
    Sep 29, 2021 12:06 AM UTC

    And what does the tointeger does in this example?