Batch processing omits sometimes items

21 views
Skip to first unread message

maie...@gmail.com

unread,
Mar 31, 2026, 7:23:29 AM (4 days ago) Mar 31
to zotero-dev
Hi, 
I have this function in my plugin:


  orderNote: {
    async addOrderNote() {
      SUL.log("Called addOrderNote from main file");
      const ZoteroPane = Zotero.getActiveZoteroPane();
      const selectedItems = ZoteroPane.getSelectedItems();
      const items = selectedItems.filter(
        (item) => item.itemTypeID === Zotero.ItemTypes.getID("book")
      );
      for (const item of items) {
        const tags = item.getTags();
        const { ddcs, orderCodes, budgetCode } = SUL.orderNote.extractTags(tags);
        const orderNote = SUL.orderNote.constructOrderNote({ ddcs, orderCodes, budgetCode });
        item.setField("volume", orderNote);
        await item.saveTx();
      }
    },

    extractTags(tags) {
      const ddcs = [];
      const orderCodes = [];
      let budgetCode = "";
      tags.forEach((tag) => {
        if (tag.tag.startsWith("DDC")) {
          const tagText = tag.tag.replace(/[^0-9X]/gi, "");
          ddcs.push(tagText);
        } else if (tag.tag.startsWith("BC")) {
          const orderCodeText = tag.tag.substring(3);
          orderCodes.push(orderCodeText);
        } else if (tag.tag.startsWith("ETAT")) {
          budgetCode = tag.tag.substring(5);
        }
      });
      return { ddcs, orderCodes, budgetCode };
    },

    constructOrderNote({ ddcs, orderCodes, budgetCode }) {
      const orderNote = [budgetCode, ddcs.join(", "), orderCodes.join(", ")].filter(Boolean);
      return orderNote.join(" // ");
    },
  },

While this works most of the time, occasionally certain items (that have the relevant tags) don't get updated. When I call the function the next time just on that specific item, everything works as expected.

Where could that fail? I don't know if there's anything wrong with my code and/or if I'm maybe interacting with Zotero incorrectly. Is it possible that the necessary is not available to my code when it runs? Or maybe the changes don't get saved?

Best,
Denis

Xiangyu Wang

unread,
Mar 31, 2026, 7:29:39 AM (4 days ago) Mar 31
to zoter...@googlegroups.com
Usually it’s helpful to add logging between steps so that you know how the execution works and data flows.

I would suspect that you might be setting the field to some items that doesn’t have the field.

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/zotero-dev/59b57d85-211b-496c-a9b8-a4d48da170d8n%40googlegroups.com.

maie...@gmail.com

unread,
Mar 31, 2026, 7:32:32 AM (4 days ago) Mar 31
to zotero-dev
Yes, I'm currently adding logging steps.
But no, I'm not setting it to items that don't have the field. If I rerun the function on just that item it usually works.

Xiangyu Wang

unread,
Mar 31, 2026, 7:34:28 AM (4 days ago) Mar 31
to zoter...@googlegroups.com
We would need the exact detailed log to help.

maie...@gmail.com

unread,
Mar 31, 2026, 9:23:44 AM (4 days ago) Mar 31
to zotero-dev
Ok, thanks. I'm adding some logging features. Let's see if I can come up with someting more useful. (Obviously, this doesn't seem to happen systematically, so it's hard to reproduce.)
Reply all
Reply to author
Forward
0 new messages