Query Tasks with Context

I want to query tasks with [[Agency Engagement]] in it that are not DONE and will show the parent block contents (the parent block will always be an agency name).

#+BEGIN_QUERY
{
 :title "Agencies with TODOs for Agency Engagement"
 :query [:find (pull ?parent [*])
         :where
           [?child :block/marker "TODO"]
           [?child :block/content ?content]
           [(clojure.string/includes? ?content "[[Agency Engagement]]")]
           [?child :block/parent ?parent]]
}
#+END_QUERY
  • For “tasks with [[Agency Engagement]]” it is more performant to do this:
    [?agency-engagement :block/original-name "Agency Engagement"]
    [?child :block/refs ?agency-engagement]
    
  • To exclude DONE, use this:
    [?child :block/marker ?marker]
    (not [(contains? #{"DONE"} ?marker)] )
    

@mentaloid, thanks. I made the update but the DONE tasks are still showing.

#+BEGIN_QUERY
{
 :title "Agencies with TODOs for Agency Engagement"
 :query [:find (pull ?parent [*])
         :where
           [?child :block/marker ?marker]
           (not [(contains? #{"DONE"} ?marker)] )
           [?child :block/content ?content]
           [?agency-engagement :block/original-name "Agency Engagement"]
           [?child :block/refs ?agency-engagement]
           [?child :block/parent ?parent]]
}
#+END_QUERY

They are still showing, because their parent is in the results, because at least one of its children is not DONE. If you want to hide such cases, should either:

  • Use some custom CSS to hide DONE tasks from queries.
    • This is convenient only if there are no complicated exceptions.
  • Instead of querying for the tasks’ parents, query for the tasks themselves, i.e. pull ?child
    • This makes more sense as a table view.
      • It is possible to still show the parent as a column.
  • Use :view to produce custom output.
    • This is much harder.

I am open to trying the CSS. The tasks exist in journals and other pages and are linked via the parent block. It is the parent block I need to show in the output. I definitely don’t have the expertise to use :view.

I gave the sample content and query to someone else and it worked perfectly.
It seems that the original query worked on a brand new graph.

Re-indexing solved the problem SMH. Thanks for responding.

@mentaloid Well I spoke too soon. I’ve discovered that 1. Re-Indexing the graph didn’t fix the problem for my colleague who uses the same graph and 2. Completed scheduled tasks still show up in the queried results.

I ultimately want to be able to query incomplete tasks pertaining to a particular agency and project type (type = Agency Engagement). I also need the query to show the agency name. I am open to restructuring my data and workflow to get this working.

Sample Data:

- [[Humber River Hospital]]
	- DONE Humber River Hospital – Omar to send training link to rep; New rep onboarded, #Daniel.Reed to reach out for MOU due to MOU missing [[Agency Engagement]]
- [[Unity Health]]
	- TODO Unity Health – Daniel to send training link to incoming reps; done [[Agency Engagement]]
- [[Mainstay Housing]]
	- TODO Mainstay Housing – sent MOU, #Daniel.Reed to follow-up to update for EY [[Agency Engagement]]
- [[CAMH]]
	- DONE Daniel to connect with Sophia and Melinda on CAMH strategy [[Agency Engagement]]
	  SCHEDULED: <2024-11-08 Fri>  
:logbook:
	  	  CLOCK: [2025-04-10 Thu 10:00:45]--[2025-04-10 Thu 10:00:46] =>  00:00:01
	  	  CLOCK: [2025-04-10 Thu 10:00:47]--[2025-04-10 Thu 10:00:48] =>  00:00:01
:END:
	- TODO #Sophia.Brown is meeting with another department at CAMH to talk about SPIDER and FOCUS, especially for gender identity clinics [[Agency Engagement]]
	- #Sophia.Brown has been meeting with CAMH for their gender identity and SAPAACY programs, CBT forensic program for Black youth, Indigenous programs; Still working with CAMH
	- CAMH – Social Determinants of Health clinic going to be covering DE and DW and ad-hoc city-wide
	- TODO CAMH – #Daniel.Reed to let #Sophia.Brown know if new MOU is not received by the end of the week. Their Social Determinants of Health Service will be joining DE and DW and is trained [[Agency Engagement]]
- [[The Neighbourhood Organization]]
	- DONE The Neighbourhood Organization – recently signed MOU. Need someone to follow up with them to ensure their incoming rep gets onboarded and trained. They also need a back-up rep. (#Melinda.Mantle to reach out) [[Agency Engagement]]
	- TODO TNO still needs to be onboarded; #Melinda.Mantle to reach out [[Agency Engagement]]
- [[Toronto Fire Reps]]
	- TODO Toronto Fire Reps – #Sophia.Brown following up and will have answer before end of the week [[Agency Engagement]]
	- TODO Internal process for Fire – time to comply with order; through community paramedicine and informed by intervention team. Emergency safety issue should be regular service. #Daniel.Reed to create document on possible Toronto Fire process at FOCUS Toronto [[Agency Engagement]]
- [[TCHC]]
	- TODO TCHC engagement still needed, #Daniel.Reed has continued to follow-up [[Agency Engagement]]
- [[The Gateway]]
	- TODO #Daniel.Reed to send #Matthew.Carrol and #Sophia.Brown an email regarding the follow up needed for S2H at YK and The Gateway at EY [[Agency Engagement]]
	- TODO #Matthew.Carrol followed up with The Gateway, need someone for S2H engagement at York. natisha.cohen@toronto.ca [[Agency Engagement]]

To hide DONE tasks:

  • in the query replace the :title line with this one:
    :title [:span {:class "hide-done"} "Agencies with TODOs for Agency Engagement"]
    
  • in file custom.css add a CSS rule like this one:
    .custom-query:has(.hide-done) .ls-block[haschild=false]:has(.done) {
      display: none;
    }