Show only first n cases in a caselist

commcare

I have a workflow that would be improved by restricting displayed cases to the first n returned cases on a caselist.

Is this possible?

Notes:

  • There could be up to 1,500 cases on a mobile device

  • Sorting is randomized (and re-randomized) regularly based on events in a separate module. It's a pretty loose algorithm for assigning the random numbers with possible duplicates. It uses MOD, which I think means they'll always be ints.

Best Answer

This can be accomplished by adding a filter based on the position() of the current element, but the syntax will be a bit of a hack because you need to introduce a second predicate filter after the current one to constrain the scope.

Example: If your current filter is

property < 50

I believe you can replace it with

property < 50][position() < N

where N is the number of results you want.

NOTE: You won't be able to see "more" cases, so the user will have go to back and forth in order to see additional results.

Update: It looks like HQ no longer allows you to use ][ to introduce a second predicate filter expression, so this doesn't work at the moment.