Performing Conditional Counting

In the case of the count() function, if the expression evaluates to null then the row is not counted.

You can supply a conditional expression to the count() function which will count only the rows where the expression returns a non-null value.

For example, to count the number of child activities for the current trouble-ticket where the Duration was over half an hour, you can use the following expression:

// Conditional expression returns non-null for rows to count
// Use the inline if/then/else operator to return 1 if the
// duration is over 0.5 hours, otherwise return null to avoid
// counting that the non-qualifying row.
def overHalfHourCount = ActivityCollection.count('nvl(Duration,0) > 0.5 ? 1 : null')