Query incomplete tasks which are not referenced from a specific page

When I’m adding new tasks, I add them to Journal pages through the course of my interstitial logging. Then I drag a block-ref to a page called “Tasks” where I prioritize them (some get grouped into project blocks, some tasks don’t have a project).

What I’d like to add is a query at the top of the “Tasks” page which lists any tasks which haven’t had a block-reference added to this page. The query below shows all my tasks and I can manually see which ones aren’t already referenced from the “Tasks” page, but I’d like to exclude them from the query results.

Tasks.md looks like:

## Inbox
	- collapsed:: true
	  #+BEGIN_QUERY
	  {
	    :title [:b "Unprioritized Tasks"]
	    :query [
	      :find (pull ?b [*])
	      :where
	        ;; ?? 
	        [?b :block/marker ?m] ;; store task state as var ?m
	        (not [(contains? #{"DONE" "CANCELED" "CANCELLED"} ?m)]) ;; exclude done tasks
	    ]
	    :breadcrumb-show? false
	    :result-transform (fn [r] (map (fn [m] (assoc m :block/collapsed? true)) r)) ;; just show the task, not the context
	  }
	  #+END_QUERY
- Ordered Tasks
	- Project 1
		- ((212d4fa5-8811-478d-8f07-af85141a79e0))
		- ((67e36827-3f7e-4244-9b5e-1b9fe88b64cf))
	- ((0ced0394-cfe9-46ba-8b6a-9b58c926576d))
	- Project 2
		- ((401cc7a2-9a2c-4373-b0d8-8b1a1dfd2d1a))
1 Like

Welcome. Something like this:

      [?tasks :block/name "tasks"]
      (not
        [?block-ref :block/page ?tasks]
        [?block-ref :block/refs ?b]
      )
1 Like

Seems to do the trick. I abstracted page name to current page in my final iteration.

#+BEGIN_QUERY
{
  :inputs [:current-page]
  :title [:b "Unprioritized Tasks"]
  :query [
    :find (pull ?b [*])
    :in $ ?pagename 
    :where
      [?b :block/marker ?m]
      (not [(contains? #{"DONE" "CANCELED" "CANCELLED"} ?m)])
      
      [?tasks :block/name ?pagename]
      (not
        [?block-ref :block/page ?tasks]
        [?block-ref :block/refs ?b]
      )
  ]
  :breadcrumb-show? false
  :group-by-page? false
}
#+END_QUERY
1 Like

I try to do a similar thing but it doesn’t work for some reason.

#+BEGIN_QUERY
 {:title "🔨 TODO notes"
    :query [:find (pull ?b [*])
            :in $ ?today 
            :where
            [?b :block/marker ?marker]
            [(contains? #{"LATER" "TODO" "DOING"} ?marker)]

            [?b :block/refs ?tag]
            [?tag :block/name "note"]

            [?dpage :block/name "Database"]
            (not
               [?block-ref :block/page ?dpage]
               [?block-ref :block/refs ?b]
             )
    ]
    :inputs [:today]
    :group-by-page? false
    :collapsed? false
}
#+END_QUERY

What I try to do here is to exclude blocks from page with name “Database”.

It is not possible to have a page with :block/name "Database" , because :block/name is always in lower-case. Either:

  • replace "Database" with "database"
  • replace :block/name with :block/original-name

For such things, have a look at the schema.

1 Like