Can I do Group By for results of api.find()?

Question

When searching the Product Extensions (or product master), it would be sometimes useful to be able to calculate SUM or AVG of certain columns. I.e., we need to make a Group By for api.find(). Is that possible?

Answer

One of the variants of api.find() has the “fields” parameter where you can define which columns you want to summarize. You can pass a map into this parameter in the format ['attribute' : 'aggregation type'], where aggregation type can be one of SUM, AVG, MIN or MAX. See the api.find() API documentation for more info.

Found an issue in documentation? Write to us.