Queries for task management

hi again,

actually it still shows a task with deadline today.
I tried to see how to exclude but I don’t get it.
Could you help me out?

{:title "📅  NEXT 3 DAYS, NOT TODAY"
    :query [:find (pull ?h [*])
            :in $ ?next ?today
            :where
            [?h :block/marker ?m]
            [(contains? #{"LATER" "TODO"} ?m)]
            (or-join [?h ?d]
              (and
                [?h :block/ref-pages ?p]
                [?p :block/journal? true]
                [?p :block/journal-day ?d])
              [?h :block/scheduled ?d]
              [?h :block/deadline ?d])
            [(and
              [(< ?d ?next)]
              [(> ?d ?today)])]]
    :inputs [:3d-after :today] 
    :table-view? false
    :breadcrumb-show? false
    :collapsed? true}
1 Like

Idk why you made such a weird query :joy:
Here’s the query as per my instructions and it works perfectly well.

{:title "📅  NEXT 3 DAYS, NOT TODAY"
    :query [:find (pull ?h [*])
            :in $ ?next ?today
            :where
            [?h :block/marker ?m]
            [(contains? #{"LATER" "TODO"} ?m)]
            (or-join [?h ?d]
              (and
                [?h :block/ref-pages ?p]
                [?p :block/journal? true]
                [?p :block/journal-day ?d]
              )
              [?h :block/scheduled ?d]
              [?h :block/deadline ?d]
            )
            [(< ?d ?next)]
            [(> ?d ?today)]
    ]
    :inputs [:3d-after :today]
    :table-view? false
    :breadcrumb-show? false
    :collapsed? true
}

Here it is a little bit more optimized, but shouldn’t change anything.

{:title "📅  NEXT 3 DAYS, NOT TODAY"
    :query [:find (pull ?h [*])
            :in $ ?next ?today
            :where
            [?h :block/marker ?m]
            [(contains? #{"LATER" "TODO"} ?m)]
            (or-join [?h ?d]
              (and
                [?h :block/refs ?p]
                [?p :block/journal-day ?d]
              )
              [?h :block/scheduled ?d]
              [?h :block/deadline ?d]
            )
            [(< ?d ?next)]
            [(> ?d ?today)]
    ]
    :inputs [:3d-after :today]
    :table-view? false
    :breadcrumb-show? false
    :collapsed? false
}

Both worked in my test environment on iPad version 0.8.16

1 Like

Tasks linked to pages with common tag.

1 Like

similar to Tasks for today based on scheduled or deadline, but without the deadline and just either tasks scheduled today or not scheduled at all on the current page:

1 Like

Hi, is it possible to for any of the queries in your OP to generate a table view of all my tasks with columns for project, deadline, priority, etc? Then can I filter and sort this table by the column values? Thanks in advance!

This is partially possible and depends on what you are looking for exactly.
For example the query under the header

Generates a table. See the :view part of the query.

Please post some example data and desired result and I’ll have a look!
Do be aware that you will not be able to filter and sort the table by the column names though. The query will just give you a static result.

Coming to simply queries:

Hi, this has been such a useful resource. Thank you!

I am starting with your “Tasks without a specific page link” and modified it a bit. I have breadcrumbs as false but I still end up getting the references for the tasks that I am pulling. Here is the code that I have

#+BEGIN_QUERY
{:title [:h3 "Tasks without page reference" ]
 :query [:find (pull ?b [*])
   :where
     [?p :block/name "habit-tracker"] ; name is always lowercase
     [?b :block/marker "TODO"]
     (not [?b :block/scheduled])
     (not [?b :block/deadline])
     (not [?b :block/refs ?p]) ; we cannot use not until we have specified the variables used in it
 ]
   :table-view? false
   :breadcrumb-show? false
}
#+END_QUERY

Can you please help to avoid having all these references, so that I can just a list of things?

You need to add

:result-transform (fn [result] (sort-by (fn [r] (get-in r [:block/created-at])) result))

Just after

:table-view? False

2 Likes

To add to @Federico_Frosini answer, any :result-transform works for this.
So something as simple as :result-transform (fn [result] result) also works.

3 Likes

Here’s the example I have in mind - I am wondering if I can get columns for project, priority, deadline, and scheduled?

Query:

#+BEGIN_QUERY
   {:title "🟠 SLIPPING"
  :query [:find (pull ?b [*])
          :in $ ?start ?today
          :where
          (task ?b #{"NOW" "LATER" "TODO" "DOING"})
          (between ?b ?start ?today)]
  :inputs [:-7d :today]
  :result-transform (fn [result]
                      (sort-by (fn [h]
                                 (get h :block/created-at)) result))
  :collapsed? true}
#+END_QUERY

Post 0.9.2 update, all my queries have gone back to show references and they are no more a list of TODO things. Did others also face similar issues?

I believe this is a solution for the issue: :result-transform and grouping of results · Issue #6641 · logseq/logseq · GitHub
Which a lot of people have asked for / complained about. (myself included lol, even though I often used result-transform to get rid of it)
There should be a way to remove the grouping, but I’m unaware if this is now available or not.
Created a feature request topic for it:

2 Likes

Thanks for the info.
I have problem also with :collapsed? Function.
Do you have any idea and solution?

Thanks

From what I read about it, seems that’s an actual bug. So would need a bug report I guess.

ok. I hope the fix it quickly.
Everyone is talking about it even in discord. :sweat_smile:

Tasks that do or do not repeat with specific tag

1 Like

That thread is a goldmine! Thank you so much @Siferiax I wonder if you could help me out. I managed to put together a query that looks for “next actions” as per the GTD terminology and keep only these “next actions” related to projects with deadlines. I just can’t seem to sort the list by :block/deadline of these ancestor blocks in the :result-transform section as the “next actions” don’t really inherit the deadlines themselves from the ancestor tasks… Here’s my query so far:

#+BEGIN_QUERY
{:title [:h2 "NEXT ACTIONS of projects w/ deadlines"]
:query [:find (pull ?b [*])
        :in $ % 
        :where
        [?b :block/marker ?marker]
        [(contains? #{"LATER" "NOW"} ?marker)]
        ;; descendant is true when ?descendant is an descendant of b

        (not [?descendant :block/parent ?b]
             [?descendant :block/marker ?amarker]
             [(contains? #{"LATER" "NOW"} ?amarker)])

(ancestor ?b ?ancestor)
[?ancestor :block/deadline ?d]
]


:inputs
   
  [[

    [(ancestor ?b ?ancestor)
				[?b :block/parent ?ancestor]]
	
    [(ancestor ?b ?ancestor)
	            [?child :block/parent ?ancestor]
	            (ancestor ?b ?child)]
]]

:result-transform  (fn [result]
                            (sort-by  
(juxt
(fn [d] (get d :block/deadline)) 
(fn [h] (get-in h [:block/properties :time]))
) < result)
)
:collapsed? false
}
#+END_QUERY#

We need to associate that deadline property with the result you get.
This happens in the :find, :keys and most importantly :result-transform of the below query.

#+BEGIN_QUERY
{:title [:h2 "NEXT ACTIONS of projects w/ deadlines"]
 :query [:find (pull ?b [*]) ?d
   :keys block deadline
   :in $ % 
   :where
     [?b :block/marker ?marker]
     [(contains? #{"LATER" "NOW"} ?marker)]
     ;; descendant is true when ?descendant is an descendant of b
     (not 
       [?descendant :block/parent ?b]
       [?descendant :block/marker ?amarker]
       [(contains? #{"LATER" "NOW"} ?amarker)]
     )
     (ancestor ?b ?ancestor)
     [?ancestor :block/deadline ?d]
 ]
 :inputs [ [
   [(ancestor ?b ?ancestor)
     [?b :block/parent ?ancestor]
   ]
   [(ancestor ?b ?ancestor)
     [?child :block/parent ?ancestor]
     (ancestor ?b ?child)
   ]
 ] ]
 :result-transform (fn [result]
   (sort-by  
     (juxt
       (fn [d] (get-in d [:block/properties :deadline])) 
       (fn [h] (get-in h [:block/properties :time]))
     )
     < 
; the below associates the deadline key from the query result with the :block/properties attribute from the block key. Which we use above in the sort.
     (map 
       (fn [m]
         (update (:block m) :block/properties
           (fn [u] (assoc u :deadline (get-in m [:deadline]) ) )
         )
       ) 
       result 
     )
   )
 )
 :collapsed? false
}
#+END_QUERY

Things are broken in version 0.9.2, but older versions should work correctly.
Let me know if you encounter any issues!

1 Like