Queries for task management

Hi all.
Anybody can help to do a query to collect all the TODO scheduled for THIS WEEK? I know I can use the next 7 days, but I would like to see the task for this week (from Monday to Sunday).
Is it possible also for THIS MONTH?

Thanks in advance

Hi,

I thought there was a topic on this but I can’t find it :smiley:
So we have no idea what week it is in the advanced query language. So there is no way to get a strict week out of it.
We can do months though! Here’s an example of that.

#+BEGIN_QUERY
{:title [:h3 "Tasks this month"]
 :inputs [:today]
 :query [:find (pull ?b [*])
  :in $ ?today
  :where
   [?b :block/marker ?m]
   [(contains? #{"TODO" "LATER"} ?m)]
   [?b :block/scheduled ?d]
   [(str ?today) ?strday]
   [(subs ?strday 0 6) ?jm]
   [(str ?jm "01") ?strstart]
   [(* ?strstart 1) ?start]
   [(str ?jm "31") ?strend]
   [(* ?strend 1) ?end]
   [(<= ?start ?d ?end)]
 ]
}
#+END_QUERY

2 Likes

Thanks as usual.
I got excited when I found +1w or +0W thinking could be next and this week, but it is not the case :frowning:

I hope in the future they will add something for the week

1 Like

@Siferiax one more thing how to add bold or highlight on the title of the advance query?

:title [:h3 "Tasks this month"]

Bold: :title [:b "Tasks this month"]
Highlight: :title [:mark "Tasks this month"]
Both: :title [:b [:mark "Tasks this month"]]

1 Like

Found the topic:

2 Likes

Thanks @Siferiax
I used it, but I got an error:

Query for unknown vars: [?b]

is it working for you?

Working now! there was two *somewhere.

1 Like

Hi all. Is there a way to make the Todo scheduled appear only after the date and time is overdue? I know how to do only date, what about time?

Unfortunately no. Time is not stored as an attribute and so is just plain text in the block content.
Likewise the only input we have for current time is an epoch timestamp and not plain text.
I feel the scheduled/deadline implementation is very lacking in that sense.
Should be a feature request to make the time an attribute in the form of epoch timestamp as well so we can more easily get the correct tasks.

2 Likes

thanks.
I agree that it is a pity

Hi all.
Do you know what is the syntax to have the TODO scheduled for today not recurring?
thanks

Add (not [?b :block/repeated? true])
This is an attribute that gets added specifically for repeating tasks.
Other tasks do not get a repeated false setting (not sure if never), so instead we check that they don’t have the attribute set to true specifically instead of checking they have it set to false.

1 Like

You know everything!!! :heart: :heart: :heart: :heart: :heart:

1 Like

Is there a way to have a table view with
| priority | Deadline | block (aka the text of the todo) | page
?
I’m trying to do this on my own with :result-transform and :view but I really cannot figure it out

Thanks for the help

1 Like

Yes, here you go:

#+BEGIN_QUERY
{:title [:h3 "Custom table"]
 :query [:find (pull ?b [*])
  :where
   [?b :block/marker "TODO"]
 ]
 :result-transform (fn [result] result)
 :view (fn [rows] [:table 
 [:thead [:tr 
   [:th "Priority"]
   [:th "Deadline"]
   [:th "Task"]
   [:th "Page"]
 ] ]
 [:tbody (for [r rows
   :let [firstline (first (str/split-lines (get r :block/content)))]
   :let [rx (re-pattern "\\[#\\w\\] ")]
   :let [content (str/replace (str/replace firstline "TODO " "") rx "")]
  ] [:tr 
   [:td (get-in r [:block/priority]) ]
   [:td (get-in r [:block/deadline]) ]
   [:td content ]
   [:td (get-in r [:block/page :block/original-name])]
 ])]
])
}
#+END_QUERY

4 Likes

Hello Siferiax.
I’ve read through all queries to try to find something I need so I can kind of adapt what I’m trying to do with tasks, but I did not find anything that is really helpful in this sense still. Perhaps a Logseq limitation?
I was going to learn datalog only so I can try to solve it myself, but this is something I need to solve as soon as possible so I can start to use this tool as it would be a perfect combination of a journal to me and a task/project management.
Okay, so this is what I’m thinking for a solution to using Logseq as a project management tool; I have it organized in a way that:

  • Each project has its own page; for subprojects (if they should exist), for now I’d keep them on the same page like sub-bullet points
  • Each project will have a set of task and subtasks that might be nested in sub sub sub… sub bullet points. An example below of a task that might have some sub tasks:
[] Fix network issues
   [] Buy router
      [x] WAIT Ask Angela for a quotation [at]angela SCHEDULED:<2023-10-10>
      [x] Approve
      [x] WAIT Angela buys it [at]angela DEADLINE:<2023-11-01>
      [] Router is delivered
   [] Install router
   [] Configure it
   

First, you’ll see some “[at]name” scattered; this is to avoid mentioning members unwillingly. So, as an example, [at]siferiax should be interpreted as @Siferiax (which is what I’m really using in Logseq)

In my example above, we can assume that the subtask “Buy router” tasks can only be achieved once the sub sub task “Router is delivered” is finished, correct? Then, once the router is delivered, I’d mark it done, then mark “buy router” done and the next tasks would be “Install router” and “Configure it”. Once it is configured, the main task “Fix network issues” would then finally be completed.
Now, what I’d like to do (and that might be too complex (or not)) was to have a query that would would show only the “Router is delivered” one in my daily journal, for example. All the other ones can be ignored.

Now, let’s imagine that no tasks are ticket; the next one would be “Ask Angela for a quotation”. You can see that the tasks that has WAIT and “[at]angela” are to be considered “delegated” tasks, but the quotation one comes before “Angela buys it”. So, here, there would be other two queries:

  • One for retrieving only Angela’s next action (quotation) and not showing the “Angela buys it” one, similar to the first one. It should handle other people as well (let’s say I have some other colleagues (Marcus, Romero, Gotardo…) scattered in Logseq (always with an “@” before the name) and it is grouped by “DEADLINE” and then by “SCHEDULED”. The point of it is going through tasks I should be checking with my colleagues when the dates are arriving.
  • Another to group “[at]angela”'s delegated tasks (let’s say that there are other nested tasks below a major parent one and even other delegated tasks in other projects. It should deal with [at]marcus, [at]romero, [at]gotardo tasks and group it by name, alphabetically. The point of this is to complement the previous one; let’s say that [at]gotardo has something with the deadline for the current week and I’ll have to talk to him; this query will show other ones that I can talk through in a meeting, for example.

I believe the last query is easy enough (I’ll try to do it myself), but for the other ones I believe that there is no solution… perhaps? If this can be implemented, my workflow would be golden. Thanks in advance, @Siferiax

Good afternoon and tell me how to make a request so that only tasks containing TODO [#A] are shown

Wow, this is amazing, thanks!

Now i could start to switch and using Logseq also for tasks.
Only problem is that on Android they don’t come in notifications.

Before i start to learn more about the logseq queries;
Would it be possible to have in this ‘task table’ the page title clickable to go directly to that page?

Yes, we need to make it a link

Replace
[:td (get-in r [:block/page :block/original-name])]

With the following

[:td [:a {:href 
       (str "#/page/" (clojure.string/replace (get-in r [:block/page :block/original-name]) "/" "%2F"))} 
         (get-in r [:block/page :block/original-name])] 
     ]
1 Like

Hello. This can be done with simple queries.
The [#A] indicates priority.
{{query (and (task TODO) (priority A))}}