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.
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;
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.