The problem seems pretty simple but I’m lost again… Too long since I practised TW
I have tiddlers with a ‘priority’ field which is a numeric value: 0, 1, 2, 3. A tiddler with undefined priority field should be interpreted as priority 0.
Given a value N, I would like to create a filter which lists all the tiddler with priority higher or equal than N.
But I cannot find a way to deal with the case where ‘priority’ is not defined, and I don’t see how to obtain the names of the tiddlers instead of their priority?
The filter gets all tiddlers. Then, for each tiddler, it gets that tiddler’s priority field value and compares it as an integer to the desired priority value. If the priority field is missing or blank, it is automatically interpreted as a 0.
Note that the :filter[...] filter run takes tiddler titles as input, and gives tiddler titles as output. Within the filter run, the <currentTiddler> is automatically set to each input title.
Do you think there is a nice way to take into account the case of tiddlers where priority is undefined, which should be considered as if it is 0? Or should I just deal with it as a special case outside the filter? (found the answer below)
If you use get[priority] instead of {!!priority} then you don’t need to use has[priority] because the get[...] filter operator implicitly does the has[...] functionality (i.e., it only returns a result if the indicated field exists AND is not empty).
However… as I noted in my suggested solution, because the compare:integer[...] operator automatically treats invalid (non-numeric) values as 0, simply doing {!!priority}compare:integer:gteq<n> is sufficient for handling the case where priority is undefined OR empty (OR is actually 0), so neither the has[...] or else[0] parts are needed to achieve your desired result.