On Contents' Notes created by Zotfile in Zotero database

edited September 28, 2023
I discovered through https://forums.zotero.org/discussion/70958/the-note-is-too-long-to-sync-shorten-the-note-and-sync-again that ZotFile auto-extract PDF table of contents using PDF bookmarks (thanks @adamsmith).

In Zotero, these notes do appear neither as notes nor as annotations to the corresponding attachment, so they cannot be deleted.

Looking at Zotero database (zotero.sqlite), It seems there is a pattern (I've just seen a few of these notes). They are saved in itemNotes table (so, they are notes) without a parentItemID (NULL value) and with itemID the same that the corresponding attachment itemID in itemAttachments table.

So, I have a couple of questions.

Are all the notes (itemNotes) with NULL parentItemID of this type (ZotFile bookmarks notes), or may there be other such notes not related to ZotFile? So, would it be safe to delete all such notes?

Isn't this behaviour a bug in ZotFile processing, so should it built notes with parentItemID (and maybe a distinct itemID)?
  • I don't know ZotFile. But the behaviour you describe is the same as for Zotero notes on attachments of items. Only notes on items themself do have theire own itemID and are listed in the items tables. Notes on attachments don't have an itemID and are not listed in the items table. Don't ask why, I'm not one of the Zotero programmers. Just like it does for you, it looks illogical to me too.

    So, if you're delete all entries in the itemNotes table with parentItemID 'NULL' you will lose Zotero notes on item attachments too. If you have such notes.

    Do a simple test (on your own risk!): make a backup copy of zotero.sqlite file and switch off auto-syncing. Now delete what you want to delete. Afterwards start Zotero again and see what you're missing. If you don't miss anything, fine. If you're missing something: delete the zotero.sqlite file and take the backup file instead and everything is as before.
  • In Zotero, these notes do appear neither as notes nor as annotations to the corresponding attachment, so they cannot be deleted.
    There seems to be some confusion here. These are embedded notes that appear in the right-hand pane when you click on an attachment. You can certainly delete them from within Zotero.

    Searching for "<strong>Contents</strong>" (with quotes) in All Fields & Tags mode should show you all of the affected notes.

    If you want to delete them, you can use this code in Tools → Developer → Run JavaScript:

    var itemIDs = await Zotero.DB.columnQueryAsync("SELECT itemID FROM items JOIN itemNotes USING (itemID) WHERE libraryID=1 AND itemTypeID=(SELECT itemTypeID FROM itemTypes WHERE typeName='attachment') AND note LIKE ?", "%<strong>Contents</strong>%");
    for (let itemID of itemIDs) {
    let item = Zotero.Items.get(itemID);
    item.setNote("");
    await item.saveTx();
    }


    You should make a backup of zotero.sqlite and turn off auto-sync first.

    Don't make direct changes to your database via SQL.
Sign In or Register to comment.