Search and replace?

Hi,

I have over 2200 articles in my library, and some of them have problems in some tags.

E.g. the latest tag I was correcting, was the abbreviation from the Journal of Physiology being 'J Phys (Lond.)' and I was removing the '(Lond.)' from it.

Would it be possible to somehow tell Zotero to change all the Journal abbreviations that have 'J Phys (Lond.)' to 'J Phys' ?

Thank you
  • Do you really mean tags or do you mean the Journal Abbr field in the metadata?

    Assuming you mean the latter, first make a backup of zotero.sqlite in your Zotero data directory with Zotero closed and then go to Tools → Developer → Run JavaScript and run this code:

    var fieldName = "journalAbbreviation";
    var oldValue = "J Phys (Lond.)";
    var newValue = "J Phys";

    var fieldID = Zotero.ItemFields.getID(fieldName);
    var s = new Zotero.Search();
    s.libraryID = Zotero.Libraries.userLibraryID;
    s.addCondition(fieldName, 'is', oldValue);
    var ids = await s.search();
    if (!ids.length) {
    return "No items found";
    }
    await Zotero.DB.executeTransaction(async function () {
    for (let id of ids) {
    let item = await Zotero.Items.getAsync(id);
    let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
    item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
    await item.save();
    }
    });
    return ids.length + " item(s) updated";
  • Thank you very much
Sign In or Register to comment.