But when I place the same code (shown below) in a function and call it, the code fails at ```QuickCopy.getContentFromItems()``` with the error message "Invalid mode 'undefined' in Zotero.QuickCopy.getContentFromItems()"
``` Javascript
// Returns the citation for the parent item.
function getParentCitation(itemID) {
console.log('Getting Parent Citation\nParent Item ID: ' + itemID);
// itemIDs for standalone notes and item notes can be passed to this function.
// Only item notes have a parent ID, so the itemID passed to this function
// for a standalone note will be null. This if/then/else statement checks
// for standalone notes and returns a blank citation in those cases.
if (!itemID) {
console.log('Standalone note. No parent.');
var citation = ' ';
} else {
console.log('Item note. Retrieving parent information.');
const parentItem = Zotero.Items.get(itemID);
console.log('Parent item: ', parentItem);
const format = '
https://www.zotero.org/styles/chicago-fullnote-bibliography'; // Chicago Manual of Style, 17th edition (full note)
console.log('Citation Format: ', format);
const biblio = Zotero.QuickCopy.getContentFromItems(new Array(parentItem), format, null, true); // Return citation for the parent item in the format specified.
var citation = biblio.html; // Copy the HTML-formatted version of the citation.
}
return citation;
}
// Returns the value of the specified field from the parent item.
function getFieldValueByItemID(itemID, fieldName) {
if (itemID) {
const parentItem = Zotero.Items.get(itemID);
fieldValue = parentItem.getField(fieldName);
} else {
fieldValue = '';
}
return fieldValue;
}
// Lists all item notes in the selected items and appends the parent reference information to the note.
// TO WORK YOU MUST EXPAND THE ITEMS AND THEN SELECT THE CHILD ITEMS AS WELL.
// Based on code by dstillman
const zoteroPane = Zotero.getActiveZoteroPane();
var noteHTML = await zoteroPane.getSelectedItems()
.filter(item => item.isNote())
.map(item => item.getNote() + '<p>Source: ' + getParentCitation(item.parentID) +
' <a href=zotero://select/library/items/' + getFieldValueByItemID(item.parentID,'key') +
'>zotero://select/library/items/' + getFieldValueByItemID(item.parentID,'key') + '</a></p>');
return noteHTML.join('<hr>');