I am trying to group the results of a search from ...
# suiteql
c
I am trying to group the results of a search from the query module and I keep getting the error
Search error occurred: Invalid or unsupported search
. I have tried:
Copy code
var queryResults = query.runSuiteQL({
    query: "SELECT tranid, entity from Transaction GROUP BY entity"
});
and
Copy code
var resultsQuery = query.create({
    type: query.Type.TRANSACTION
});
resultsQuery.columns = [
    resultsQuery.createColumn({
        fieldId: 'tranid',
    }),
    resultsQuery.createColumn({
        fieldId: 'entity',
        groupBy: true
    }),
];
var results = resultsQuery.run();
Removing the grouping from my queries resolves the error and returns results. Am I doing something wrong here?
c
If you're going to GROUP, you need to either group or run aggregate/analytic functions on all non-grouped columns
What's the purpose of selecting the
tranid
but excluding it from grouping above?
c
Thank you, I did not realize that I had to either group or aggregate the remaining columns. That was just a basic example because I was trying to sanity check myself. I'm just getting started with the query module.
c
Gotcha! I've only stumbled over this particular thing eleventy hundred times
Good luck with your query journey! This is a good channel to help you if you start to wander 😄