Tasks query that shows all tasks that are existing in (the current note's) outgoing links. #2392
-
Hello everyone, My goal:A query that shows all tasks that are existing in the current note's outgoing links. Why:I have many projects (single notes that contain many tasks; henceforth referred to as "sub-projects"). Example:I have 1 note called "Obsidian task management.md" (this would be the super-project) I would love to add wikilinks of the 3 sub-projects into the super-project. [[tasks plugin]]
[[CSS for tasks]]
[[taxonomy of tags in tasks]] While the 3 sub-project notes would contain different tasks: - [ ] Open thread on GitHub to figure out the query code I can't get working myself.
- [ ] Think about which of the custom statuses are most useful and how to relate them to each other. "CSS for tasks.md" could contain: - [ ] Figure out how to reduce the space between tasks.
- [ ] Figure out how to change custom status symbols or add new ones. "taxonomy of tags in tasks.md" could contain: - [ ] Add #TSKalmostdone to tasks are basically finished but need a last check (ideally at a moment I'm not tired or stressed)
- [ ] Add #TSKquicky to tasks that should be finished within 10 minutes, so I can later query them for when I want to be productive but I'm short on time. The Tasks query (that I'm trying to create) would show, at the bottom of "obisidian task management.md", all the tasks that are included in the 3 sub-projects (ideally grouped), which would render as something like this: # tasks plugin
- [ ] Open thread on GitHub to figure out the query code I can't get working myself.
- [ ] Think about which of the custom statuses are most useful and how to realte them to each other.
# CSS for tasks
- [ ] Figure out how to reduce the space between tasks.
- [ ] Figure out how to change custom status symbols or add new ones.
# taxonomy of tags in tasks
- [ ] Add #TSKalmostdone to tasks are basically finished but need a last check (ideally at a moment I'm not tired or stressed)
- [ ] Add #TSKquicky to tasks that should be finished within 10 minutes, so I can later query them for when I want to be productive but I'm short on time. Possible solutions (that aren't scaling properly):I'm aware that I could list the 3 sub-projects in the Tasks query, by manually typing them out in And there are probably more "simple" ways like that. What I have so far:While I couldn't find a solution for a Tasks query, I found a thread in the official Obsidian forums. dataviewjs
// get all unique outlinks without .png and current note
let notes = dv.current().file.outlinks
.map(x => x.path)
.filter((value, index, self) => index === self.indexOf(value))
.where(x => !x.endsWith("png") && x != dv.current().file.path);
// create empty array
let arr = [];
// push notes element to empty array
arr.push(dv.current().file.path);
notes.map(y => arr.push(y));
// printing tasks from unique outlinks
let ntasks = arr.map(x => dv.page(x).file.tasks.where(t => !t.completed));
ntasks.map(x => x.length > 0 && dv.taskList(x)); What's left to do:The above code shows what I want, but it does so in Dataview and not Tasks (which I greatly prefer). I've tried to add the Dataview code from above into the example code of the Tasks documention, but can't get it to produce the result I want. I tried many different ways of inserting the code but, thanks to my lack of understanding the code in the first place, to no avail so far. Here's one example of how I tried to combine them: dataviewjs
const query = `
${let notes = dv.current().file.outlinks
.map(x => x.path)
.filter((value, index, self) => index === self.indexOf(value))
.where(x => !x.endsWith("png") && x != dv.current().file.path);
let arr = [];
arr.push(dv.current().file.path);
notes.map(y => arr.push(y));
let ntasks = arr.map(x => dv.page(x).file.tasks.where(t => !t.completed));
ntasks.map(x => x.length > 0 && dv.taskList(x));}
# you can add any number of extra Tasks instructions, for example:
# group by heading
limit 10
`;
dv.paragraph('```tasks\n' + query + '\n```'); I would hope that someone who's more knowledgeable about code could help me either:
Thanks so much in advance and let me know if anything is unclear or needs more information! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
@superjangooo - OK here it is... I don't normally ask for donations in support queries, but this took a lot of time, and so I've added my donations link as a comment in the query, in case anyone who reads this feels that they are able to support the development of the Tasks plugin. ```dataviewjs
/*
PURPOSE: Tasks query that shows all tasks that are existing in (the current note's) outgoing links
https://github.com/obsidian-tasks-group/obsidian-tasks/discussions/2392
Tasks query logic code written by Clare Macrae
Donations invited, to support the development of Tasks:
https://github.com/sponsors/claremacrae
Limitations:
- Works in Tasks 5.0.0 or above/
- Tasks search will not work if any of the file paths has a ( or ) character anywhere in the path.
*/
// Get all unique outlinks without .png and current note
// Credit for these 4 lines:
// by: [aboode95](https://forum.obsidian.md/u/aboode95)
// in: https://forum.obsidian.md/t/dataview-dataviewjs-how-to-fetch-tasks-that-are-in-the-outgoing-links-of-a-note/66176/16
let paths = dv.current().file.outlinks
.map(x => x.path)
.filter((value, index, self) => index === self.indexOf(value))
.where(x => !x.endsWith("png") && x != dv.current().file.path);
// Create a list of Tasks path filters, one for each outlink path:
const pathFilters = paths.map((path) => `( path includes ${path} )`);
// Join the Tasks path filters in to a Boolean OR query.
let filterForOutlinks = pathFilters.join(' OR \\\n');
// Construct the Tasks query string:
const tasksQuery = `
# Note that as of Tasks 5.0.0, this search will fail if any
# of the outlinks have a ( or ) anywhere in their paths:
${filterForOutlinks}
not done
group by filename
# Any other Tasks instructions can be added to this.
# Get an explanation of the Tasks query.
# Comment this out once you are happy with the results:
explain
`;
// For debug purposes, write out the Tasks query as text.
// Remove this once you are happy with the results:
dv.paragraph('```text\n' + tasksQuery + '\n```');
// Finally, run the Tasks sarch
dv.paragraph('```tasks\n' + tasksQuery + '\n```');
``` An example generated Tasks query block is:
|
Beta Was this translation helpful? Give feedback.
-
This is amazing, greatly improves obsidian tasks' project management potential. For reference, using The lack of supports of bracket(s) anywhere in the filepath (also as of 6.0.0) is proving to be quite a challenge in a few of my notes though, any way in which we can escape the brackets or work around this limitation? |
Beta Was this translation helpful? Give feedback.
-
I think you can base on this query somehow
|
Beta Was this translation helpful? Give feedback.
@superjangooo - OK here it is...
I don't normally ask for donations in support queries, but this took a lot of time, and so I've added my donations link as a comment in the query, in case anyone who reads this feels that they are able to support the development of the Tasks plugin.