Best Way To Replace Many Notes Programmatically #4634
-
I am writing a little script that loads a bunch of web views. However, existing notes in the target folder should simply be overwritten in order to avoid the need to do so by hand. A simple way to do this would be to store their id as a label and then for every note before creating search for their label and delete any note found. Another way would be to just delete the entire parent note and recreate it or delete everything in the parent note. I feel like this is a relatively common issue. Any "way to go" solutions for that issue? Backend Code// api url to access
var url = 'https://ilaris-online.de/api/ilaris/kreatur/';
async function fetchData() {
// waits until promise becomes get response
const response = await fetch(url);
if (!response.ok) {
api.log("Not OK!")
throw new Error(`HTTP error! Status: ${response.status}`);
}
const kreaturen = await response.json();
// for simplification we just use the first element
api.log(kreaturen[0].name)
// get folder holding all webViews later
const kreaturenRoot = api.getNoteWithLabel('kreaturenRoot');
// create new webView and set source accordingly using the label
const resp = api.createNewNote({
parentNoteId: kreaturenRoot.noteId,
title: kreaturen[0].name,
type: "webView",
content: ''
});
resp.note.setLabel("webViewSrc", "https://ilaris-online.de/app/kreatur/" + kreaturen[0].id);
}
fetchData(); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Sorry, I don't understand why you need to update Anyway, your approach looks fine. But, You may not need an extra label as an ID since |
Beta Was this translation helpful? Give feedback.
-
Just deleting an existing note and creating it again (like you have in your script) should be OK ... |
Beta Was this translation helpful? Give feedback.
Just deleting an existing note and creating it again (like you have in your script) should be OK ...