Do backend scripts work? #5897
-
Hey!
... but again, nothing happens. What am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 2 replies
-
Hi, module.exports = async ({ triliumScriptApi }) => {
const {
getNote,
createNote,
setNoteContent
} = triliumScriptApi; Where did you get this syntax? Did you use an LLM to help you write the script?
In addition:
A working script would look like this: async function main() {
const sourceNoteId = "Fh5Q2oLkKZ37";
const targetParentNoteId = "XwPzPkpZ8tR6";
const sourceNote = await api.getNote(sourceNoteId);
await api.createTextNote(targetParentNoteId, `[COPY] ${sourceNote.title}`, sourceNote.getContent());
}
main(); |
Beta Was this translation helpful? Give feedback.
-
LOL, yes! 🤦 Either way, thank you for the quick response! This makes more sense now and should be enough to get me started on what I'm trying to achieve. |
Beta Was this translation helpful? Give feedback.
Hi,
Where did you get this syntax? Did you use an LLM to help you write the script?
Either way, this is incorrect due to two reasons:
module.exports
is generally used only for widgets and not backend scripts.triliumScriptApi
. The API resides withinapi
and it's best to simply callapi.foo
.In addition:
await
it means that we need anasync function
. But you also need to call the function in order to ensure it does something (otherwise it's just an expression).createNote
is a deprecated API and relatively …