diff --git a/src/modules/template/api.ts b/src/modules/template/api.ts index 762fdb9..b4b8d0e 100644 --- a/src/modules/template/api.ts +++ b/src/modules/template/api.ts @@ -147,7 +147,12 @@ async function runItemTemplate( return ""; } - const targetNoteItem = Zotero.Items.get(targetNoteId || -1); + let targetNoteItem: Zotero.Item | undefined = Zotero.Items.get( + targetNoteId || -1, + ); + if (!targetNoteItem) { + targetNoteItem = undefined; + } const items = itemIds?.map((id) => Zotero.Items.get(id)) || [];