I’d like to add to this query so that it also pulls any tasks that are NOW, no matter what scheduled date they have (or even if they don’t have one).
In other words, “Give me a list that combines every open task scheduled for today or earlier (regardless workflow status) and all tasks with the workflow status of NOW (regardless of scheduling, even if it has no scheduling), ordered by schedule date.”
Every arrangement of “and” or “or” that I use, though, just brings up no results.
It’s close. It doesn’t include a “NOW” task with no scheduled date. “[?b :block/scheduled ?d]” comes up empty on those, so those fail to meet the criteria of the query.
I keep playing around with it to see if I can get that resolved, but I keep coming up with 0 results. For example, this is a small tweak on yours (just moves that one statement down) and looks ot me like it should work, but it comes up empty.
This feels like it should work as saying: get me everything that has a scheduled date and that date is today or earlier, OR everything with a NOW state.
You defined ?d in the same and that you wanted to use it in. I guess, that the clauses inside the and are separated (their variables are only unified after both are evaluated).
What happens in my possible solution
the get-else function takes
a database ($)
an entity identifier (?b)
an attribute (:block/scheduled)
a default value (?tomorrow)
and returns the entities attribute-value, or the default value, if it fails.
So [(get-else $ ?b :block/scheduled ?tomorrow) ?d] unifies ?d with either the scheduled date, or if there is none, with ?tomorrow.
Afterwards we can obviously check for either marker being “NOW” or schedule date being at most ?today (which, in particular, ?tomorrow is not).
I only used the tomorrow’s date as a default value, because it’s bigger than today’s (that way stuff that isn’t a “NOW” and is not scheduled, gets a value that makes the or-evaluation false).
Maybe it would be better to use some “Maximum date” value, but I don’t know whether that exists.
add (not [(contains? #{"DONE" "CANCELED"} ?m)]) (for example right below [?b :block/marker ?m])
I love to cancel some tasks if I see they became irrelevant. Feel free to remove the “CANCELED” from the set, if you don’t use it.
To be honest, for some strange reason the query does not longer do what it should do.
On my system it ignores whether the task is scheduled or whether it has a deadline. Probably there is something wrong with get-else.
But aside from that (maybe I will debug the rest of the query, maybe someone else will), it should be