how to edit blank key values in a batch
var fieldName = "language";
var oldValue = " ";
var newValue = "en";
188BET靠谱吗var fieldID = Zotero.ItemFields.getID(fieldName);
188BET靠谱吗var s = new Zotero.Search();
188BET靠谱吗s.libraryID = ZoteroPane.getSelectedLibraryID();
s.addCondition(fieldName, 'is', oldValue);
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
188BET靠谱吗await Zotero.DB.executeTransaction(async function () {
for (let id of ids) {
188BET靠谱吗let item = await Zotero.Items.getAsync(id);
188BET靠谱吗let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ?mappedFieldID : fieldID, newValue);
await item.save();
}
});
return ids.length + " item(s) updated";
var oldValue = " ";
var newValue = "en";
188BET靠谱吗var fieldID = Zotero.ItemFields.getID(fieldName);
188BET靠谱吗var s = new Zotero.Search();
188BET靠谱吗s.libraryID = ZoteroPane.getSelectedLibraryID();
s.addCondition(fieldName, 'is', oldValue);
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
188BET靠谱吗await Zotero.DB.executeTransaction(async function () {
for (let id of ids) {
188BET靠谱吗let item = await Zotero.Items.getAsync(id);
188BET靠谱吗let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ?mappedFieldID : fieldID, newValue);
await item.save();
}
});
return ids.length + " item(s) updated";
"" not " "
SyntaxError: unexpected token: identifier
var oldValue = "" not " ";
var newValue = "en";
188BET靠谱吗var fieldID = Zotero.ItemFields.getID(fieldName);
188BET靠谱吗var s = new Zotero.Search();
188BET靠谱吗s.libraryID = ZoteroPane.getSelectedLibraryID();
s.addCondition(fieldName, 'is', oldValue);
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
188BET靠谱吗await Zotero.DB.executeTransaction(async function () {
for (let id of ids) {
188BET靠谱吗let item = await Zotero.Items.getAsync(id);
188BET靠谱吗let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ?mappedFieldID : fieldID, newValue);
await item.save();
}
});
return ids.length + " item(s) updated";
这是我所使用的:
Copy
{"itemType": "book", "language": "en"}
to the clipboard and use Zutilo's "Paste into empty item fields".The "itemType" name/value pair needs to be kept for technical reasons, its value is irrelevant for this function.Also, remember to 188BET靠谱吗back up your Zotero data188BET靠谱吗, in particular your 'zotero.sqlite' database.Running code that you are not sure about can have unwanted results.