Numbered Notes

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I am using Metdata menu and Templater. I have Dataview as well
i have multiple Templates that some income metadata.
I want all this note that i will create i want them to auto create a note number (1,2 3,…500) in the meta data.

I searched but i haven’t found something similiar

Any ideas??

in your new note template:

---
id: <% tp.user.idnext(tp) %>
---

in idnext.js in your templater scripts directory:

async function id_next(tp) {
    const options = await app.plugins.plugins.dataview.api.query('TABLE id FROM -"template" WHERE typeof(id) = "number" SORT id desc LIMIT 1')
    let result = options.value.values[0][1]+1
    return result
}
module.exports = id_next;
1 Like

Thank you for that, but clearly i am doing something wrong here

While i add this on the Metadata menu

you got the first part right!

this method doesn’t use metadata menu (though I don’t think it conflicts with it). It does require templater and dataview.

What you need is to set up the templater plugin’s script folder:

and then in there is where you make that idnext.js file.
That way the templater code you put in the frontmatter will run it when it executes.

EDIT:
I double checked and the code wasn’t quite right. The script should instead look like this:

async function idnext(tp) {
    const options = await app.plugins.plugins.dataview.api.query('TABLE id FROM -"template" WHERE typeof(id) = "number" SORT id desc LIMIT 1')
    console.log(options.value)
    try{
        var result = options.value.values[0][1]+1
    }catch(err){var result = 1}
    return result
}
module.exports = idnext;

that way if it finds no previous ids, it assigns 1.

It’s probably not too hard to make this code a bit more generic and work with a given property name, but for now it should be easy enough to tweak for your purposes.

1 Like

I appreciate the help,

Clearly i am doing something wrong here :sweat_smile:

I will try again later with a clear mind!

for now i will take a more simple approach!

1 Like

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