[Share] [Custom-Template] Run selected Better Notes template for current item #319
ramonmi
started this conversation in
Action Scripts
Replies: 1 comment 2 replies
-
/**
* Select the Better Notes template when triggering the shortcut.
* @author windingwind, ramonmi
* @usage Trigger with shortcuts
* @link https://github.com/windingwind/zotero-actions-tags/discussions/319
* @see https://github.com/windingwind/zotero-actions-tags/discussions/319
* @ref https://github.com/windingwind/zotero-better-notes/issues/1250
*/
if (!Zotero.BetterNotes?.api.note?.insert) {
return "[Custom-Template] Better Notes for Zotero > 1.1.4-21 is not installed or disabled.";
}
if (!item) { return; }
// Select template name from input
templateName = (await Zotero.BetterNotes.hooks.onShowTemplatePicker("pick"))[0]
templateContent = Zotero.BetterNotes.api.template.getTemplateText(templateName);
if (!templateContent) {
return "[Custom-Template] Template is invalid";
}
// Define refreshable template array
// change the array with your template names with refreshable content
// Hint: [item] or [text] mush be lower case!
const templateArray = ['[item]item_Academic_Vocabulary','[item]item_Extensive_Reading','[item]item_Flow_Notes','[item]item_Intensive_Reading','[item]item_Tag_Journal'];
// check if the template have refreshable content
if (templateName && templateArray.includes(templateName)) {
var refreshableTag = "refreshable-template";
}
const parentItem = Zotero.Items.getTopLevel([item])[0];
const noteItem = new Zotero.Item("note");
noteItem.libraryID = parentItem.libraryID;
noteItem.parentID = parentItem.id;
if (refreshableTag) {
noteItem.addTag(refreshableTag, 0);
}
await noteItem.saveTx();
let html = "";
html = await Zotero.BetterNotes.api.template.runItemTemplate(templateName, {
itemIds: [parentItem.id],
targetNoteId: noteItem.id,
});
await Zotero.BetterNotes.api.note.insert(
noteItem,
html,
-1,
);
return `[Custom-Template] Note ${noteItem.getNoteTitle()} is created on item ${item.getField("title")} from template ${templateName}`; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
Event
None
Operation
Script
Data
Anything else
Beta Was this translation helpful? Give feedback.
All reactions