Intended method for plugins to access Item fields?

23 views
Skip to first unread message

Lucas Myers

unread,
Apr 20, 2026, 2:40:21 PM (4 days ago) Apr 20
to zotero-dev
Hi,

My intention is to access the text, notes, and keys associated with annotations on creation. To that end, I've used the Notification system detailed here. Using the `Zotero.Notifier.registerObserver` method one may get the `id` of items created, and then the `Zotero.Items.get` (or `Zotero.Items.getAsync`) method may be used to retrieve an item.

However, it appears that all the fields of the Annotation items (and perhaps others) have an underscore prefix, giving me the impression they're not intended to be accessed directly. In the "Get information about an item" section of the "Zotero Javascript API" here, it appears we're supposed to use the `getField` method. When I call it with "id" as input, it gives me the proper Item id, but when used to get "annotationText" it comes back null -- this leads me to believe the method works on fields of the base class, but not superclasses. How should I go about accessing the "annotationText" field?

Relatedly, that section indicates a TODO to list all possible fields. Where in the source would I look to figure out the possible fields? And when I figure it out, how can I contribute to the documentation?

Kind regards,
Lucas

Dan Stillman

unread,
Apr 20, 2026, 2:46:35 PM (4 days ago) Apr 20
to zoter...@googlegroups.com
annotationType, annotationText, annotationComment, etc. Defined here:

https://github.com/zotero/zotero/blob/a835136d3b7c7f4589ec2df9bac3039c5717e93a/chrome/content/zotero/xpcom/data/item.js#L4201

You can click on an attachment with annotations in the items list and run this in Tools → Developer → Run JavaScript to see some examples:

ZoteroPane.getSelectedItems()[0].getAnnotations()

Tests are also usually a pretty good reference:

https://github.com/zotero/zotero/blob/main/test/tests/annotationsTest.js

Lucas Myers

unread,
Apr 20, 2026, 5:34:38 PM (4 days ago) Apr 20
to zotero-dev
Hi Dan,

Thanks for the quick response, but I'm a bit confused by what you're saying. I figured out the fields of Annotation objects by printing an Annotation received from `Zotero.Items.get`. My problem is that if I use `item.getField("annotationText")`, it gives an empty string. I could directly call `item._annotationText`, but the underscore prefix makes me think this should be treated as a private field.

I haven't been able to get `getAnnotations()` to work (I don't know what attachment I'm supposed to click on), but I assume it returns an array of Annotation objects -- I want to know how to access their fields.

- Lucas

XY Wong

unread,
Apr 21, 2026, 5:01:14 AM (3 days ago) Apr 21
to zotero-dev
The getAnnotations() works on attachment items. You'll need to select an attachment item with annotations.

The props Dan mentioned above are not fields. Use `item.annotationText`.

For your reference

2. the docs about the data model with frequently used props/methods: https://windingwind.github.io/doc-for-zotero-plugin-dev/main/zotero-data-model.html#item
Reply all
Reply to author
Forward
0 new messages