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?
Discussion posts and replies are publicly visible
i think its because in iteration 2 i dont have a rate available on that item, how do I go around that?
Hi pedrob0002
Have you tried index?
tointeger(index(local!queryrating,"rating_average",null))
Regards,
Acacio B
And what does the tointeger does in this example?
and how should I use it in my example?
In your sample code you are assign the value of rating_average to your local local!ratestar, however at some moment as you mentioned that value is null thus you are getting the error that you describe, the index() is to ensure that you have a default value for the null situation and the toInteger() is to guarantee the expected type.
Probably you are handling the null local!ratestar in your code, so if you add the code that I send as an example to your local and handle the null you should not have error.
Hope that helps,
Acacio B.
I've tried it but still doesn't work, is there any other solution?
Hi Pedro,
Can you provide a little more context, what is the error that you are facing now? Please share a bigger snapshot of your Sail code as well.
I've already managed to make it work, had to use 2 index functions in my query expression.
Thank you anyways.