Created
March 24, 2015 15:41
-
-
Save bwiernik/06b3cdd93b7602813aac to your computer and use it in GitHub Desktop.
Batch edit item language to de for German items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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