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");
}
  • Hey, the problem has been resolved.

    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.
  • The Javascript API also includes functions for finding Collection IDs or making arrays of the items in a particular collection:

    https://www.zotero.org/support/dev/client_coding/javascript_api
  • @bwiernik: Oh yeah.... thanx for that...
Sign In or Register to comment.