How to delete the content of the extra field for all references

Hello,

A plug-in has filled the ‘extra’ field of my entire library with information that I do not wish to mention and that appears when exporting bibliographies.
Is there a way to delete the information in the extra field of all references in the library without modifying each reference individually (it contains 3,200 documents and this would take a very long time...)

Thank you for your help !
  • tnajdek Zotero Team
    edited April 24, 2025
    Not with the UI, but it’s possible with a little bit of scripting. Since this will affect many items, I strongly recommend making a backup of your Zotero directory before proceeding. See: https://www.zotero.org/support/zotero_data

    Once your data is securely backed up, you can follow these steps to clear the value of the "extra" field in all selected items:

    1. Select the items you’d like to modify (use Cmd/Ctrl+A in the root of your library to select all).
    2. From the menu bar, choose Tools → Developer → Run JavaScript.
    3. Tick "Run as async function"
    4. Paste the following code:

    let clearExtra = async (i) => {
    if (i.isRegularItem()) {
    i.setField("extra", "");
    await i.saveTx();
    }
    };

    await Promise.all(
    ZoteroPane.getSelectedItems().map(i => clearExtra(i))
    );


    5. Press Run.

    (I've edited the code few minutes after posting initially to make sure it correctly waits for the changes to execute)
  • thank you so much !
  • yes, saved me a lot of time, many thanks!
  • Thank you for this script. Can someone please tell me the reference name to the "Book author" field? I would like to use the script to empty lots of these fields that are erroneous in some "Book section" items I have. I have tried "book-author", "bookAuthor", "container-author" (I saw that mentioned somehow in discussion #22403), and "containerAuthor", but none of them were valid. Thank you in advance.
  • tnajdek Zotero Team
    edited 9 days ago
    Firstly, for regular fields, custom script is no longer needed. Latest beta supports batch editing. However, current implementation does not support batch-editing authors yet.

    The following script will remove ALL book authors from EVERY SELECTED book section item. Same instructions as before (Run as async function).

    Before applying, please see my warning about scripting and backup from the original message.

    let bookSectionID = Zotero.ItemTypes.getID("bookSection");
    let bookAuthorID = Zotero.CreatorTypes.getID("bookAuthor");

    let clearBookAuthors = async (i) => {
    if (i.itemTypeID !== bookSectionID) {
    return;
    }
    let creators = i.getCreators().filter(c => c.creatorTypeID !== bookAuthorID);
    if (creators.length === i.numCreators()) {
    return;
    }
    i.setCreators(creators);
    await i.saveTx();
    };

    await Promise.all(
    ZoteroPane.getSelectedItems().map(i => clearBookAuthors(i))
    );

  • In addition, the Linter plugin allows you to clean only the specified content in the extra field. It can scan the extra field of the selected items and list the specific content for you to choose:

    https://s3.amazonaws.com/zotero.org/images/forums/u7424907/5it537hvvnaob73m1bpg.png
Sign In or Register to comment.