Filter tasks dynamically based on a list in file properties #3484
-
Hi everyone, I’m trying to filter tasks dynamically based on a list stored in file properties (Frontmatter). Specifically, I have a property called task-filter-status, which contains multiple status names as an array (e.g., ["In_Progress", "Waiting"]). I want to write a Tasks query that automatically filters tasks based on this list, without manually adding each status with OR. Here’s what I tried: filter by function task => task.file.property("task-filter-status")?.includes(task.status.name) ?? false Unfortunately, this results in an error:
Even though task-filter-status is correctly defined as a list in the file properties, the query doesn’t seem to recognize it properly. Has anyone successfully used filter by function to reference a list from file properties? Is there another way to make this work? Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@JohannaHerbst, I'm happy to help, but please help me to help you.
Put it in a fenced code block, so that I can reliably copy-and-paste the text in to Obsidian.
Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Goal:I want to dynamically filter tasks based on the Below I included an example in Dataview to illustrate what I'm aiming at. Dynamic Filter with Dataview
Thank you very much |
Beta Was this translation helpful? Give feedback.
Solution
Here you go:
Make sure you paste it all on one line, or use Lines Continuations (
\
) to break the line up.Assumptions made
task-filter-status-view
property is always provided, and the value is always a listtask.file.property()
was the right function, rather thanquery.file.property()
How it works
It uses
Array.includes()
to return true of any of the values in the property match the predicate.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
The…