Remove Citation Key from Extra Field

edited June 18, 2023
I would like to harmonise the citation keys in my Zotero library. Half the items don't have a manually specified citation key, so when I export a .bib file, an automatic key is generated (format: author_firstwordoftitle_YEAR). In the other half, the Extra field contains a manually specified citation key (format: "Citation Key: AuthorYEAR"), which is used when I create a .bib file. I would like to drop the citation keys in the Extra field.

Since this affects about 1000 items, I would prefer not to have to do this by hand. I've tried to use the JavaScript API, but didn't get very far with the code I got out of ChatGPT. Has anyone here encountered and solved a similar problem?

Thanks in advance!

P.S.: Here is a version of the code I tried to run and the resulting error:

var zoteroItems = await Zotero.Items.getAll();
await Zotero.DB.executeTransaction(async function () {
for (let i=0; i<zoteroItems.length; i++) {
let item = zoteroItems[i];
let extra = item.getField('extra');
if (extra.includes('Citation Key:')) {
let lines = extra.split('\n');
lines = lines.filter(line => !line.startsWith('Citation Key:'));
extra = lines.join('\n');
item.setField('extra', extra);
await item.saveTx();
}
}
});


Error: Parameters not provided for query containing placeholders [QUERY: SELECT A.itemID FROM items A WHERE 1 AND A.itemID NOT IN (SELECT itemID FROM deletedItems) AND libraryID=?]
  • If you set these keys using BBT, you can just select all, right click, and select BBT - unpin from the popup menu.
  • I suspect the forum ate some of your code because what we see here is not valid javascript. You can enclose your code in <code>...</code> and it will display as you wrote it.
Sign In or Register to comment.