Hi there !
So, I don’t really have an issue to solve (as I’ve already found a solution ) but there’s something I would like to understand when it comes to Dataview Tasks list, tasks and subtasks in a note and I would really appreciate some clarifications from the Dataview Experts out here
!
What I was trying to do:
Well, I was trying to get a Dataview tasks list containing only “parent” tasks (i.e.: containing no potential subtasks/children of any kind)
So, for the context, consider this bit of note living somewhere in my vault:
- [ ] Task 1 [project:: Project 1]
- [ ] Task 1 [project:: Project 2]
- [ ] Task 2 [project:: Project 1]
- [ ] Task 2.1 [project:: Project 1]
- [ ] Task 2.2 [project:: Project 1]
- [ ] Task 2.3 [project:: Project 1]
From there, I wanted to get a Dataview tasks list for the tasks where the project
key had the value "Project 1"
and was solely a “parent task”.
So the result of the query should have been something like:
- [ ] Task 1 [project:: Project 1]
- [ ] Task 2 [project:: Project 1]
Trying to keep it simple, I first created a DQL:
```dataview
TASK
WHERE project = "Project 1" AND !children
```
… which gave some results but not the ones I was expecting, especially the !children
As this did effectively return the tasks tied to "Project 1"
only but instead of returning the Task 2
, it returned the whole list of subtasks tied to it:
… and this is what I don’t understand :
Why can’t I just negate the presence of any possible subtasks in a task, in DQL ?
I mean, I tried variations of solution I found (see below) in DQL but either the query didn’t return any result at all (without errors) or the results were still not quite the expected one
I’m really not used to query tasks lists with Dataview (and I try to avoid having to deal with subtasks/sublists), so there’s probably something I don’t know about how tasks lists work in Dataview, or something I’m missing or I’m just generally mistaken and misunderstand the general concept behind tasks list in Dataview
…
Hence why I’m here .
Things I done to get to my desired result:
I asked in the #Dataview
channel on Obsidian Discord Server and was told that I should probably switch to DataviewJS
to filter out the undesired subtasks
I tried but was still stuck .
Thinking this would be a common Dataview use case, I searched in the Discussions
of the Dataview GitHub repo and stumbled upon an answer which worked perfectly (Thank you Holroy
)
So, I ended up with this DVJS query :
```dataviewjs
const parentTasks = dv.pages().file.tasks
.filter(t => t.children = [])
.where(p => p.project === "Project 1")
dv.taskList(parentTasks)
```
Which, even though it doesn’t return the appropriate count of tasks ( ), at least, it displays all the tasks I wanted to see
!
I also guess that another way to make it work would have been to not tie any project
key to the subtasks so wouldn’t have to try and exclude them from any query …
Thank you so very much in advance to anyone who could point me what I’m probably missing in all this
!!!