a!queryEntity( entity: cons!AS_DataStore_Ratings_Pointer, query: a!query( aggregation: a!queryAggregation( aggregationColumns: { a!queryAggregationColumn( field: "productId", isGrouping: true ), a!queryAggregationColumn( field: "rating", alias: "rating_average", aggregationFunction: "AVG" ) } ), logicalExpression: a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "productId", operator: "=", value: ri!productId ) }, ignoreFiltersWithEmptyValues: true ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 50 ) ), fetchTotalCount: false ).data
Hi!
so i have this query which return the average of a value from an ID, but not all items have rating and when i. use it in a foreach i get this error:
Interface Definition: Expression evaluation error at function a!forEach [line 63]: Error in a!forEach() expression during iteration 3: Expression evaluation error: Invalid index: Cannot index property 'average_rating' of type String into type List of Variant
it says during iteration 3 because its the first time there is no rating on a specific item. Any help?
Discussion posts and replies are publicly visible
Use the index() or property() function to access individual fields instead of the dot-notation.
in the query expression or in the interface? because i've tried both funtion on the interface and it didnt work
Stefan is correct that you should use index() or property() to prevent errors within your a!forEach() function. That being said, it also looks like you're using a different name in both places. In your query the alias is called "rating_average", but your error message above says you're using "average_rating" to index the results.
yes I've spotted that later, changed it but still doesn't work
Can you post the full expression (not only the query)? I'm curious how you're using the a!forEach() and if that is causing an issue.
1s, its a pretty long expression