Dynamic link to open tasks in weekly note using dataview/tasks plugins


I’ve done some searching around and have tried various solutions but am coming up empty (perhaps also because I am an absolute beginner), so I’m trying my luck here. Maybe one of you has an idea.

What I’m trying to do

I’m using Periodic Notes with daily and weekly notes, as well as the tasks and dataview plugins. I’ve created a tasks dashboard note that displays tasks due at various dates using dataview queries. That all works great.
Now I’d like to add a section to this note that dynamically shows all unfinished and unscheduled tasks from my current weekly note - this is where I’m stuck.

Things I have tried

I created a query that displays all unfinished tasks from the current weekly note - so far, so good:

.where(t => !t.completed)

But I fail when I try to input a dynamic link to the respective weekly note, instead of manually linking to this week’s note. My format for the weekly notes is gggg-[W]ww. Any ideas what I would have to input in exchange of “2023-W16” in the above query?

This may be related to a more general problem with creating dynamic links.

I can create simple backlinks to the current weekly note like so: [[2023-W16]].
But I cannot create a dynamic backlink - in other threads I’ve found solutions like [[{{date:gggg-[W]ww}}]], which were reported to work without the Templater plugin, but I get an error message that file names cannot contain “:”. I’m wondering if the command is even recognised. Do I need to install an additional plugin?

Any ideas would be much appreciated!

Thank you :slight_smile:

{{date:gggg-[W]ww}} is a template tag. You put it in a template, and when you trigger the template you get the current date formatted as specified. I’m not sure how you tried to use it, but it sounds like you clicked on [[{{date:gggg-[W]ww}}]], which would create a note literally named {{date:gggg-[W]ww}}, which isn’t allowed because of the colon.

That query, and in particular the dv.pages('"2023-W16"')... doesn’t list tasks from a weekly note, but a weekly folder. So either you’ve not copied the query the folder correctly, or do you have all of your daily notes within a weekly folder? Please clarify.

And if you’ve got a weekly note, like a note named 2023-W16 does that contain the definitions of the tasks, or does that have a query listing all task defined for that week (pulled in from other daily notes)? If the latter, you can’t pull the result of a query into another query. You’d then need to repeat the query once more at the other location.

Finally, if you weekly note does contain the task definitions, and your query is something more like dv.page('"2023-W16"')...., the following could be used to replace that static weekly string with the current week:

dv.taskList( dv.page(`"${ moment().format("gggg[-W]ww") }"`)
  .file.tasks.where( t => !t.completed ) )

Here we use moment() to get the current day, and format that to give us the correct format. If your query actually was correct, please do change it back to be dv.pages, and not dv.page

Thank you both very much for your patient advice.

I realised I’m even more clueless than I thought :smiling_face_with_tear:
@CawlinTeffid Accordingly I very likely misread something in the forum thread where I was getting the {{date:}} idea from.

I’ve now read better documentation and have realised some of my errors.

@holroy I do not have all my daily notes in a weekly folder - just edited the query badly. Current weekly notes are in the main vault directly under /. I move them to an archive folder only once the week is done, so the moving hopefully shouldn’t impact any code for the current week.

The weekly notes contain the definitions of tasks (if I understand correctly that this means the - [ ]).

The query you suggested returns an error message “cannot read properties of undefined” (I’m still trying to understand why); but if I do switch page out for pages like you also recommended, it successfully displays all open tasks from the current weekly note :tada:

I’m now also using the same query to dynamically display open tasks from the current daily note. It’s great! Thank you very much.

I’ll wait and see if it manages to switch over to the next daily/weekly note soon, but I’m feeling hopeful :blush: Will report, and highlight your answer if it works.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.