Query to generate a table with the todos including columns with the deadline, schedule date and priority

I would like to kindly ask if anyone knows how to create a table using an advance query where each row corresponds to a todo task and has additional columns for Scheduled date, deadline and priority. So, the table view of the query would be like:

Title | Status | Scheduled date | Deadline | Priority

task 1 | todo | 2021-08-08 | | A

Thanks in advance,
Fernando

I have been able to find a solution using this approach:

#+BEGIN_QUERY
{:title “Scheduled”
:query [:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[?b :block/scheduled ?d]
[(!= “DONE” ?marker)]
]
:result-transform (fn [result]
(->> result
(map (fn [r] (assoc r :block/properties {“scheduled” (get r :block/scheduled)})))
)
)
:collapsed? False}
#+END_QUERY

Unfortuntately, the date format is yyyymmdd. It would be nicer to have a better format like yyyy-mm-dd HH:MM. So, if anyone has a solution for that it would be very appreciated .

In the meantime, the current solution is good enough to create arbitrary tables based on Tasks information.

Regards.

3 Likes

It took me a couple of minutes to figure out quotation marks needs to be adjusted…
Allow me to paste a version that can be pasted directly into logseq.

#+BEGIN_QUERY
{
   :title "Scheduled"
   :query [:find (pull ?b [*])
      :where
      [?b :block/marker ?marker]
      [?b :block/scheduled ?d]
      [(!= "DONE" ?marker)]
   ]
   :result-transform (fn [result]
      (->> result
         (map (fn [r] (assoc r :block/properties {"scheduled" (get r :block/scheduled)})))
      )
   )
   :collapsed? False
}
#+END_QUERY
3 Likes

this is brilliant! I’m quite a newbie to the query syntax and want to know how to put deadline at the beginning of a row? thanks!

I create 4 query to create GTD board:

  • DOING (just copy from tutorial example)
  • Scheduled
#+BEGIN_QUERY
{
	:title "🍻 It's time to make it happen"
    :query [
    	:find (pull ?h [*])
        :in $ ?start ?next
        :where
        [?h :block/marker ?marker]
        [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
        ;; filter by scheduled or deadline
        (or [?h :block/scheduled ?d] [?h :block/deadline ?d])
        [(>= ?d ?start)]
        [(< ?d ?next)]
    ]
    ;; in next week
  	:inputs [:today :7d-after]
    :result-transform (fn [result]
    					(sort-by (fn [h]
                        			(get h :block/priority "Z")) result))
    :collapsed? false}
#+END_QUERY
  • Next (high priority but not hurry)
#+BEGIN_QUERY
{
	:title "🏄 Nnnnnext"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
            ;; double not to implement (A or B or C) = !(!A and !B and !C)
            (not
            	(not
                	[?h :block/priority ?priority]
	         		[(contains? #{"A" "B" "C"} ?priority)]
                )
                (not 
                	[?h :block/ref-pages ?p]
         			[?p :page/name ?page-name]
		         	[(clojure.string/includes? ?page-name "okr")]
                )
            )]
    :result-transform (fn [result]
    					(sort-by (fn [h]
                        			(get h :block/priority "Z")) result))
    :collapsed? false}
#+END_QUERY
  • Others (low priority)
;; like Next, but use not directly
...
(not
        	[?h :block/priority ?priority]
        	[(contains? #{"A" "B" "C"} ?priority)]
        )
        (not 
        	[?h :block/ref-pages ?p]
 	       	[?p :page/name ?page-name]
    	    [(clojure.string/includes? ?page-name "okr")]
        )
        (not
        	(or [?h :block/scheduled ?d] [?h :block/deadline ?d])
        	[(>= ?d ?start)]
        	[(< ?d ?next)]
        ) 
...
2 Likes