Advanced query to search TODOs in active projects

Hello, unfortunately I am completely lost in the world of advanced queries. I know nothing, nothing at all about programming, I must admit. It also took me a long time to find how to insert them into a page (the tutorial materials, why don’t they start with the first step?). Well, anyway, I tried to put together a query based on the wealth of advice here. Of course, I failed. So I’m asking for concrete help instead.

I keep track of the projects as attached. What I would like to achieve: to extract TODOs from active projects. Could someone help me with this, what should be the query? Thank you very much in advance!

Here is a query to begin with:

#+BEGIN_QUERY
{
 :query [:find (pull ?block [* ])
 :in $ %
 :where
   [?block :block/page ?page]
   [?block :block/marker ?marker]
   [(contains? #{"TODO"} ?marker)]

   (ancestor ?a ?block)
   [?a :block/properties ?props]
   [(get ?props :status) ?status]
   [(= ?status "active")]
 ]
 :inputs [
   [
     [
       [ancestor ?a ?b]
       [?b :block/parent ?a]
     ]
     [
       [ancestor ?a ?b]
       [?parent :block/parent ?a]
       (ancestor ?parent ?b)
     ]
   ]
 ]
}
#+END_QUERY

The exact format of your notes is unclear, so you may need to add/remove parts from/to that query.

1 Like

thank you! how can i add projects to the query?

What does this mean? Please try making more specific questions. Do you mean this?

[(get ?props :tags) ?tags]
[(= ?tags "Projects")]
1 Like

I usually open a separate page for projects, I have photographed the structure, you can see it in the screenshot attached to the original post, I mark the page with a projects tag and the tasks are placed underneath.

I would like to collect the tasks of the projects marked as active.

That’s the part mentaloid posted. You need to add that to the query they posted earlier.
After the line [(= ?status "active")]
And before the line with ].

1 Like

thank you both very much, you are fantastic.

Given your new info, you may get away with this:

#+BEGIN_QUERY
{:query [:find (pull ?block [*])
   :where
     [?block :block/marker ?marker]
     [(contains? #{"TODO"} ?marker)]
     [?block :block/page ?page]

     [?page :block/tags ?tag]
     [?tag :block/original-name "Projects"]

     [?page :block/properties ?props]
     [(get ?props :status) ?status]
     [(= ?status "active")]
 ]
}
#+END_QUERY
3 Likes