Dataview query next action tasks

Hi, I am trying to show tasks which have #nextaction appended to them. But every query I run will only show the file where the tasks are located. I want to display the task itself and exclude any tasks that do not have #nextaction next to them.
For example a file “actions” may contain 3 actions/todos
[] action 1
[] action 2
[] action 3 #nextaction

I want a query that will only show me action 3.

What I’m trying to do

1 Like

Hi.
Post here your start query.
Then we see how to filter them (explaining why your query doesn’t work).

You might consider the Tasks plugin as well as you can add a description includes #nextaction line in the query to limit it

2 Likes

Hey, I don’t know if the way you’re trying to format your next action is the easiest way, like @takeo says, the Tasks plugin may be more appropriate

However, a simple solution to your issue could be achieved with dataviewJS in the following way:

dv.taskList(dv.pages("#testtag").file.tasks.where(t => t.text.includes("#nextaction")))

Where #testtag is whatever folder/criteria you want to filter your notes by. Dataview in its simplest form simply returns tasks from the pages that satisfy your conditions. You can’t apply conditions to the tasks themselves unless you use DataviewJS

Note: your code block would have to start with “dataviewjs”, have a look here for more info :slight_smile:

Not true. You can achieve the same goal with simple DQL queries.

TASK
FROM #nextaction
WHERE contains(text, "#nextaction")

I just didn’t give the solution in my first post because the need to understand the difference between the definition of the source - the tag as a page level metadata - and the filter of tag in each task (by text or, in new beta version, by tag inside tasks).

With some start query we can explain things; post only the solution it’s less pedagogic.

2 Likes

Hi @mnvwvnm my apologies, a misunderstanding on my part! That’s really useful to know,

And I agree with you about pedagogy!

2 Likes

This is great. Is there a way to make this a column in a DQL Table query?

So I have a table with a list of projects and column that shows me incomplete tasks tagged with next in against each of the project?

Thanks.

you can get tasks in table… but only the task text, not the checkbox. I.e., you can’t have dynamic checkbox (to check/uncheck)

I actually managed to build a hacky solution to include the checkbox by putting a dvjs inline query in a nextactions field in the queried note. But it seems like an overly complex solution and I actually only need the text of the task and not the checkbox itself.

nextaction:: $= dv.taskList(dv.page('Make improvements to Ficus Ruby Theme').file.tasks.where(t => !t.completed).limit(5).where(t => t.text.includes('#next')), false)

table nextaction AS "Next Action", length(file.tasks.text) as Total, "<progress value='" + (length(filter(file.tasks.completed, (t) => t = true)) / length(file.tasks.text)) * 100 + "' max='100'></progress>" AS Progress
from #Project/Active and -"0. Meta"

So I managed to display the text of all tasks that are tagged with #next with the below:

filter(file.tasks.text, (t) => contains(t, "#next"))

But I just can’t seem to wrap my head around how I would filter that result down further to only include tasks that are incomplete.

Any help would be greatly appreciated :slight_smile:

The main problem is: you want to keep access to other values to get the total and build your progress bar.
If that wasn’t the case, then you could use the flatten command and after apply some where conditions to filter the desired tasks.
But that isn’t the case…
So, you can try something like:

filter(file.tasks, (t) => contains(t.text, "#next") & !t.completed).text
2 Likes

Works perfectly.

Just to play back what I have learnt (as this was my first foray into using DQL functions):

Step 1: This returns the task objects from each queried file. This is a great way to see all of the key-values associated with tasks so the results can be filtered further or a specific type of value can be returned

file.tasks

Step 2: The filter function returns an array of all of the tasks objects for each queried file. we define this array as t. We then filter out using “!” the task objects where completed = true.
filter(file.tasks, (t) => !t.completed)

My mistake when trying to filter file.tasks.text was that I was narrowing it down to the text key-value too early which was preventing me from being able to also filter on other key-values like completed.

Step 3: Further filter down the task objects for each file for all tasks that contain #next in their text key-value. Contains takes the variable t which is our tasks object, we narrow that down to the text key so we are working with the returned text and we want to return the text values that contain “#next”. We then combine that with the not complete filter in the previous step by using the “&” operator.

filter(file.tasks, (t) => contains(t.text, "#next") & !t.completed)

Step 4: We now have the all of the tasks objects that we want so the last step is to define that we only want to see the text value. We do this by appending “.text” to the query.

filter(file.tasks, (t) => contains(t.text, "#next")&!t.completed).text

Hopefully I didn’t butcher the terminology too much. This really helped my understanding. Thanks :slight_smile:

3 Likes

Thank you so much for sharing this. I’ve been trying to get my project dataview table to work with all this information for a while now. This example answered all my questions, as well as, adding the next action which is so helpful! This is such a great community willing to share their knowledge to those of us just starting out.

Also, what snippet or style setting are you using for your table?

1 Like

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