Search and Replace based on Collection ID using JS
Hi, guys I am trying to do a search and replace using Javascript. It works but when I try to filter out using CollectionID, it fails. I obtained my CollectionID by seeing the end of the URL of my library collection.
What I am I doing wrong?? Here is the code:
======CODE STARTS========
var fieldName = "archiveLocation";
var newValue = "001";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition('collectionID', 'is', 'BCLL4NGS');
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, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
What I am I doing wrong?? Here is the code:
======CODE STARTS========
var fieldName = "archiveLocation";
var newValue = "001";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition('collectionID', 'is', 'BCLL4NGS');
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, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
I was using wrong collectionID. collectionID is not obtained by seeing the end of the URL of library collection. collectionID is the value that I had to look up from the sqlite database. It is present in the "collections" table.
https://www.zotero.org/support/dev/client_coding/javascript_api