getting parent item in a group library

120 views
Skip to first unread message

EluisiveOctopus

unread,
Jun 13, 2022, 2:52:28 PM6/13/22
to zotero-dev
Hello,
API question

I'm writing a plugin with code similar to the following -- which is stolen from this plugin: https://github.com/UB-Mannheim/zotero-ocr/blob/master/chrome/content/zoteroocr.js#L98

It works when I have a pdf selected on my personal 'My library' sub-collection, but when I use it on something selected in a sub-collection in my 'group library' I get errors like (below).  The errors happen with the zotero-ocr plugin as well so maybe I shouldn't be basing my logic off that plugin and that's my problem.

[JavaScript Error: "Parent item 1/4Q5DY97J not found" {file: "chrome://zotero/content/xpcom/data/item.js" line: 1537}]

Is there something obvious that I'm doing wrong here?

Thanks!
basic code is the following (error above):


let basestr = "myfile"';
let item = Zotero.getActiveZoteroPane().getSelectedItems()[0];
let parentitem = Zotero.Items.get(item.parentItemID);
yield Zotero.Attachments.importFromFile({
file: basestr + '.pdf',
parentItemID: parentitem.id
});
thanks!

EluisiveOctopus

unread,
Feb 28, 2023, 1:04:56 PM2/28/23
to zotero-dev
Hello,
I was wondering if any Zotero developers have any ideas about how I could get around this? It seems to still be occurring with the newest version of Zotero.

volatile static

unread,
Mar 1, 2023, 10:36:52 PM3/1/23
to zotero-dev
Hello,
The API ` Zotero.Items.get` is a synchronized method, it loads item from caches. Some item that in group library may not loaded into cache, so you should use async method ` Zotero.Items.getAsync`.

Dan Stillman

unread,
Mar 2, 2023, 12:46:12 AM3/2/23
to zoter...@googlegroups.com
No, sync vs. async wouldn't be the issue here — the code is using getSelectedItems(), so the items are already loaded.

We'd need to see exact minimal code that triggers this in the Run JavaScript window. The given code works fine for me on a child attachment in a group library.
--
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 on the web visit https://groups.google.com/d/msgid/zotero-dev/9f0a97e1-e1dd-478f-942b-4de4ef2b2c50n%40googlegroups.com.

Dan Farrell

unread,
Mar 2, 2023, 11:01:43 AM3/2/23
to zoter...@googlegroups.com
Here is a minimal reproducible example.  Missingobjecterror is returned in a group library but not in my own personal library.

let basestr = "CONTENTSSSS";

let item = Zotero.getActiveZoteroPane().getSelectedItems()[0];
let parentitem = Zotero.Items.get(item.parentItemID);
let newNote = new Zotero.Item('note')
newNote.setNote(basestr);
newNote.parentID = parentitem.id;
await newNote.saveTx();
newNote

image.png
image.png



You received this message because you are subscribed to a topic in the Google Groups "zotero-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotero-dev/LVmcjIMqYvA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/01000186a0db4538-43a285dc-f3af-4bd0-ab22-0b1df42df1a5-000000%40email.amazonses.com.

Abe Jellinek

unread,
Mar 2, 2023, 11:17:27 AM3/2/23
to zoter...@googlegroups.com
Add:

newNote.libraryID = item.libraryID;

Setting parent[Item]ID doesn’t set libraryID, so it defaults to the user library and then fails because the user library doesn’t have an item with the parent item's key. (I think that’s a bug - we should set libraryID along with parentKey - but I’ll let others weigh in.)

On Mar 2, 2023, at 11:01 AM, Dan Farrell <d...@cyrusbio.com> wrote:

Here is a minimal reproducible example.  Missingobjecterror is returned in a group library but not in my own personal library.

let basestr = "CONTENTSSSS";
let item = Zotero.getActiveZoteroPane().getSelectedItems()[0];
let parentitem = Zotero.Items.get(item.parentItemID);
let newNote = new Zotero.Item('note')
newNote.setNote(basestr);
newNote.parentID = parentitem.id;
await newNote.saveTx();
newNote

<image.png>
<image.png>


Message has been deleted

EluisiveOctopus

unread,
Mar 2, 2023, 2:33:22 PM3/2/23
to zotero-dev
That is perfect! Thanks so much!

Dan Stillman

unread,
Mar 2, 2023, 5:41:11 PM3/2/23
to zoter...@googlegroups.com
On 3/2/23 11:17 AM, Abe Jellinek wrote:
Add:

newNote.libraryID = item.libraryID;

Setting parent[Item]ID doesn’t set libraryID, so it defaults to the user library and then fails because the user library doesn’t have an item with the parent item's key. (I think that’s a bug - we should set libraryID along with parentKey - but I’ll let others weigh in.)

Yeah, this is a bug. We set libraryID automatically for child attachments when parent[Item]ID is used, so we should do the same for child notes.

EluisiveOctopus

unread,
Mar 10, 2023, 1:47:44 PM3/10/23
to zotero-dev
In this same vein:

attachments.linkFromFile (and the relative path version) do not appear to take "libraryID" as an option/argument
Reply all
Reply to author
Forward
0 new messages