I am trying to do the following for my project notes. If I am creating a new project note via a template, I would like to have a “Project ID” that counts up so I can use that ID as a filter in dataview.
The frontmatter I currently use (and update manually) is:
“Project 1” has “projectid” “P001”; I create a new note “Project 2”; I am adding my project template to that note; the fontmatter updates the “projectid” to “P002”.
Is this somehow possible? I heard the “templater” plugin is able to do that, but I can’t figure out how, because I am too unfamiliar with it.
First you need a convenient place to stash your current project value. I chose to use a simple text file, which I stored in the same folder as my other Templater scripts. The only content in this file is the current value.
Then I set up a Templater template as follows.
//get a handle on the counter file
const counter = tp.file.find_tfile('project-counter.txt');
//read the current counter value
let count = parseInt(await app.vault.read(counter));
//increment the count
//save the updated counter value
projectid: P<% count.toString().padStart(3,'0') %>
<% tp.file.cursor() %>
Note, this template assumes you’re applying this template to a blank note. If you need something more advanced that creates the note and stores it in a particular location, there are examples of doing that sort of thing floating around.
Wouldn’t it be just as easy to do a Dataview query, and select the highest project id, and then increment that? Is it needed to actually store the project id in a file of its own?
On a related note, how many projects are you like to create during a month/year? Would it be a viable alternative to just use some combination of the year and day-of-year to generate project ids, i.e. 22349 (for day 349 of '22)? They would not be sequential, but then again you would know when you started (or thought of) that particular project. For me such project ids would be a little easier to remember than pure sequential numbers (but this is a matter of personal preferences, for sure)
And if you feel up for it, I would strongly consider setting up templater to trigger the new project note for new files within your project folder. So that when you create a new file in there, (or hit a particular hot key,) it setups the new project for you, properly with ID’s, tags, and what-not.
Hi everyone —
Thank you very much for your suggestions.
I need to be honest, I found a way easier way to solve my initial problem. The “Project ID” was just a workaround because I didn’t know that there was a way to use the …
where contains(Project, [])
… query to have the file name automatically updated in dataview if I would ever change it. (That’s why I wanted to use a “Product ID” that stays consistent)
This also means (for future readers of this thread) that I can’t confirm if the proposed solution works or not.
Still, thank you very much for taking the time and proposing a solution.