Batch edit entries
I have multiple entries that feature the same field content. It's an archive that has changed name, and I need to update the name. As there are hundreds of entries, I'd rather not do this one by one, but as a single 'search and replace' operation.
Is that doable directly in Zotero?
Is that doable manually in the database and what does it take for that?
Thanks for your help!
Is that doable directly in Zotero?
Is that doable manually in the database and what does it take for that?
Thanks for your help!
Doing that directly in the database would require running an sqlite client. Unless you know what you're doing in sqlite, that's not recommended.
with:
var fieldname = "archive";
var oldValue = "Old Name";
var newValue = "New Name";
I need to search author names such as "Charles S Prebish", without a dot after middle initial, and replace with "Charles S. Prebish" with a dot after middle initiale.
What fieldName should I enter in the Javascript API?
var fieldName="";
var oldValue = "Charles S Prebish";
var newValue = "Charles S. Prebish";
Would this code line works?
var fieldName = "creators.firstName";
var oldValue = "Charles S.";
var newValue = "Charles S";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition(fieldName, 'is', oldValue);
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");
}
Result is:
Invalid condition 'creators.firstName' in hasOperator()
Creators have their own syntax via getCreator (you can see it used in some of the examples further up on that page)
What page is it? Can you give me the link?
I haven't thought this through, but since implementing the search via API looks like it would take a bit of code, you could just do the search in Zotero, create a saved search, and then just work with items in the saved search, loop through the creators in that and change the first name where applicable. I haven't worked with the js api so the exact syntax would take me some time to figure out, too, so unless Gracile knows this right away you're likely on your own with that.
edit: btw. you can use the <blockquote> tag for quotes.
I'm not a programmer myself... I'm editing my Ph. D. thesis so that it is conform to my university style. I have hundreds of references to check and edit, and a search/replace function would have been essential to this task.
The Execute JS API can be used to edit data in the Zotero Advanced Research pop-up window only (with the API, you choose whatever Firefox window you want to work with). How can I use the API at this point?
@gracile
What then would be the final code, using
http://www.zotero.org/support/dev/client_coding/javascript_api#adding_items_and_modifying_data
and the JS search/replace loop above?
you mentioned this function would be implemented with a new release of Zotero. Is this still to come? Or have I missed something in the menu on how to get this done?
edit: or otherwise - work with the search condition - i.e. set the old Value to % and the search condition operator to 'does not contain'
and for empty string: No items found. Any suggestions?
I'm not 100% sure the wildcard will work, but I think it will.
I set:
var fieldName = "language";
var oldValue = "%";
var newValue = "en";
I want to change blank language fields to en. I have the .js file ready (https://gist.github.com/zuphilip/b942c8bf2f1126982517) I have saved a search with all my Lang=blank items in it and have that open in Zotero Standalone. I have installed ExecuteJS, invoked it in Firefox, pasted in my code. The next instruction is
"In Execute JS, switch the target window to an open browser window, paste the relevant code into the “JS-Code to execute” box, make any necessary changes, and click “Execute”. "
Any old browser window will do? OK, choose a Google tab. Execute. And I get "TypeError: this.collectionsView.selection is undefined." I'm actually quite relieved nothing worse happened, as this process makes no sense to me. There seems to be a big hole in the instructions that is probably painfully easy to anyone who has done this before, but I have not. Can anyone give me a step-by-step on batch editing? Thanks!
Zotero Version 4.0.29.10
Short answer: that can't work with Zotero Standalone.
"In Execute JS, switch the target window to a Zotero browser window with the relevant records selected, paste the relevant code into the “JS-Code to execute” box, make any necessary changes, and click “Execute”. "
It may also be useful for others who follow this path to know that JS Execute installs in Firefox without a visible trace. In order to invoke it, you have to show menus and find it in your tools menu.
The batch edit code now works perfectly.