A list of next tasks grouped by projects

Hi,
I need help with implementing a query for my task management system.

It’s all set up quite simply. There are projects, which are pages with the property type:: proj.
Tasks are always written only on diary pages and are linked to projects via a reference, for example, TODO Task1 [[Project1]]. From all the tasks in a project, one should be marked with the #next tag, like TODO Task1 [[Project1]] #next.

I want to get an output, a list (or table, doesn’t matter) of tasks with the next tag, grouped by project.
Something like this:

Project1  
    [ ] Task for project 1 #next  
Project2  
    [ ] Task for project 2 #next  

And so on.

What’s important is that I want all projects to be included in the results, even those that don’t have tasks with the next tag. So that it’s clear that there’s no such task in the project and it needs to be created.

Is it possible to do this using an advanced query?

I have programming experience, but Datalog just drives me crazy.

1 Like

Something like this:

#+BEGIN_QUERY
{
 :query [:find ?p-name (pull ?b [*])
   :keys p b
   :where
     [?next :block/name "next"]
     [?p :block/name ?p-name]
     [?p :block/properties ?props]
     [(get ?props :type) ?type]
     [(= ?type "proj")]
     (or-join [?next ?p ?b]
       (and
         [?b :block/refs ?p]
         [?b :block/refs ?next]
       )
       (and
         (not
           [?t :block/refs ?p]
           [?t :block/refs ?next]
         )
         [?b :block/name "next"]
       )
     )
 ]
 :result-transform (fn [results]
   (map (fn [r]
     (update (:b r) :block/properties (fn [p]
       (assoc p "project" (:p r) )
     ) )
   ) results)
 )
}
#+END_QUERY
2 Likes

Hi, and thank you for the response. This query gives me this result. It’s not quite what I wanted.

The tasks are not grouped by projects.

There is an extra empty line before the visible tasks, I suppose that represents the missing task from Project 3.

  • Switch to table view.
  • Use the cogwheel to adjust the desired columns and their order.

Yes, much better now! Exactly what I wanted.
Thank you so much for your help!