Skip to content

Instantly share code, notes, and snippets.

@bwiernik
Created March 24, 2015 15:41
Show Gist options
  • Save bwiernik/06b3cdd93b7602813aac to your computer and use it in GitHub Desktop.
Save bwiernik/06b3cdd93b7602813aac to your computer and use it in GitHub Desktop.
Batch edit item language to de for German items
var fieldName = "title";
var fieldName2 = "language";
var oldValue = "für";
var newValue = "de";
var fieldID = Zotero.ItemFields.getID(fieldName);
var fieldID2 = Zotero.ItemFields.getID(fieldName2);
var s = new Zotero.Search;
s.addCondition(fieldName, 'contains', oldValue);
s.addCondition("itemType", 'isNot', "attachment");
var ids = s.search();
if (ids) {
for each(var id in ids) {
var item = Zotero.Items.get(id);
var mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName2);
item.setField(mappedFieldID ? mappedFieldID : fieldID2, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment