SQL script to clear contents of Extra fields
Using different citation count addons has led to my Extra fields becoming an unsortable mess, so I would like to batch clear them before running zotero-citationcounts which does precisely what I want to do.
Simply running zotero-citationcounts is not enough, since it does not overwrite the Extra field but simply appends citations to old entries, including those from outdated citation addons. This is unlikely to change in future versions (see https://github.com/eschnett/zotero-citationcounts/issues/2).
I would like to do this in any way possible, including raw SQL scripts. Yes, I do understand the risks involved.
There is an old thread from 2010 about this issue (https://forums.zotero.org/discussion/12992/a-way-to-delete-all-info-from-all-extra-fields). The proposed SQL script there sadly does not work as of 2021-01-21.
Simply running zotero-citationcounts is not enough, since it does not overwrite the Extra field but simply appends citations to old entries, including those from outdated citation addons. This is unlikely to change in future versions (see https://github.com/eschnett/zotero-citationcounts/issues/2).
I would like to do this in any way possible, including raw SQL scripts. Yes, I do understand the risks involved.
There is an old thread from 2010 about this issue (https://forums.zotero.org/discussion/12992/a-way-to-delete-all-info-from-all-extra-fields). The proposed SQL script there sadly does not work as of 2021-01-21.
https://www.zotero.org/support/dev/client_coding/javascript_api
var fieldName = "extra";
var newValue = "";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search();
s.libraryID = ZoteroPane.getSelectedLibraryID();
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
await Zotero.DB.executeTransaction(async function () {
for (let id of ids) {
let item = await Zotero.Items.getAsync(id);
let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
await item.save();
}
});
return ids.length + " item(s) updated";