Dataview - tasks from project based on metadata

Hi im trying to make a querry that will give me back all incomplete tasks from all project grouped by project.

I got i done for one project:

task 
where contains(projekt, "ProjectName") and !completed
group by projekt

i was trying to do this in js

dv.taskList(dv.pages().file.tasks
.where(t => !t.completed).where(p => p.projekt = "ProjectName"))

but its not working…

also i got this:

dv.list(dv.pages('"Projekty"').where(p=>p.projekt).where(p=>p.projekt !=1).where(p=>p.fileClass != "newnote").projekt)

which give me a list of all acitive projects and i want to combine those 2 into one query that will give task from the project form the list.

Not sure if this is going to work but maybe you could try this :

```dataview
TASK
WHERE projekt AND !completed
GROUP BY projekt AS "Projekt"
```

The WHERE projekt part should return all the tasks tied to a projekt key (regardless of the name of the project)

I don’t know how you added metadata to your tasks so I can’t say how it’s going to work in your vault…
I used inline fields to quickly test the query above which gave me this result :

The first part was working ok but i wanted to do more with this.

Each page in my vault has YAML metadata with “projekt” with one more projects the note is refering to.

I wanted to do a querry in dataviewjs that will to 2 things:

  1. check to list of acitive projects:
dv.list(
dv.pages('"Projekty"') // folder with all project Moc
.where(p=>p.projekt)
.where(p=>p.status !="koniec") // Project ended status
.where(p=>p.fileClass != "Mysl")  // this class is for random notes
.projekt)
  1. then do the querry:
task 
where contains(projekt, "projects from the list in 1)") and !completed
group by projekt

i was trying to do this in js and got to:

dv.taskList(
dv.pages()
.where(p=>p.projekt)
.file.tasks
.where(t=>!t.completed)
)

but i dont how to combine the 1) and 2) into one.

I do hope a more experienced DataviewJS user will see your post and provide the right query :sweat_smile:

In the meantime, maybe this ? :

```dataviewjs
dv.taskList(
	dv.pages('"Projekty"').file.tasks
		.where(p => p.project)
		.where(p => p.status != "koniec")
		.where(p=> p.fileClass != "Mysl")
		.where(t => !t.completed)
		.groupBy(p => p.project)
)
```

(From my tests, .where() needed to be applied on dv.pages("").file.tasks… The query didn’t return anything the other way around dv.pages("").where().file.tasks)

I couldn’t test this with status and fileClass but it seemed to work from my side of the screen :innocent:

Not quite was i was going for -

  • this will find tasks from pages in “Projekty” from active Projects

the goal was to take the list of active procjet form the folder

dv.list(
dv.pages('"Projekty"') // folder with all project Moc
.where(p=>p.projekt)
.where(p=>p.status !="koniec") // Project ended status
.where(p=>p.fileClass != "Mysl")  // this class is for random notes
.projekt)

and search all pages in vault for notes with project from the list. Then gather all not done tasks from notes that meet the criteria above, and goup them by Project names (from the list)

Ok so i made some progress:

i have this ready

function zadaniaTest(dv, query) 
{
   dv.taskList(
dv.pages()
.where(p=>p.projekt ==query )
.file.tasks
.where(t=>!t.completed)
)
} 

zadaniaTest(
    dv,
    "PKM" //project name
)

and the list of active projects

dv.list(dv.pages('"Projekty"').where(p=>p.projekt).where(p=>p.status !="koniec").where(p=>p.fileClass != "Mysl").projekt)

but i dont know how to combine it…

Got it :slight_smile:


var NowaLista = 
dv.array(dv.pages('"Projekty"').where(p=>p.projekt).where(p=>p.status !="koniec").where(p=>p.fileClass != "Mysl").projekt)
;

function zadaniaTest(dv, projects) {
  for (var i = 0; i < projects.length; i++) {
    var tasks = dv.pages()
      .where(p => p.projekt == projects[i])
      .file.tasks
      .where(t => !t.completed)
      ;
    if (tasks.length > 0) {
      dv.header(3, projects[i]);
      dv.taskList(tasks);
    }
  }
}

zadaniaTest(dv, NowaLista);

1 Like

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