How to create summary filters such as Max, Count, ...
# ask-stanley-ai
a
How to create summary filters such as Max, Count, and Sum in a search expression in SuiteScript?
c
AI generated answer (using internal Slack threads):
In SuiteScript, you can create summary filters such as Max, Count, and Sum in a search expression by using the
search.createFilter()
method or filter expressions. However, it's important to note that summary filters require at least one group summary column. Here is an example of how to create a summary filter using `search.createFilter()`:
Copy code
javascript
search.createFilter({
    name: 'formulanumeric',
    formula: "CASE WHEN {task.custevent_taak_type.id} = 4 AND {task.status.id} != 'COMPLETE' THEN {task.internalid} ELSE null END",
    operator: 'is',
    values: "1",
    summary: search.Summary.COUNT,
})
And here is an example of how to create a summary filter using filter expressions:
Copy code
javascript
[
    "formulanumeric: CASE WHEN count(CASE WHEN {task.custevent_taak_type.id} = 4 AND {task.status.id} != 'COMPLETE' THEN {task.internalid} ELSE null END) = 3 THEN 1 ELSE" +
    " 0 END",
    "is",
    "1",
]
In the above examples, the
search.Summary.COUNT
is used to count the number of tasks that meet the specified criteria. For summing up two different columns in a saved search, you can use a formula with the summary type Maximum:
Copy code
javascript
SUM(column1) + SUM(column2)
For using the Max summary filter, you can use a filter expression like this:
Copy code
javascript
[
    "max(formulanumeric: case when {file.name} like '%asnFileCabinet%' then 1 else 0 end)",
    "equalto",
    "0"
]
Remember, when using summary filters, you need to ensure that your search does what it's supposed to do. Always double-check your search to make sure it works as expected. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.853637695
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840576172
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83416748
Please provide your feedback on this answer.