mgmeyers / obsidian-zotero-integration

Insert and import citations, bibliographies, notes, and PDF annotations from Zotero into Obsidian.
GNU General Public License v3.0
1.09k stars 55 forks source link

[BUG] runImport can't access group libraries #314

Closed FeralFlora closed 8 months ago

FeralFlora commented 1 year ago

While Zotero Integration can import from group libraries, it seems that this capability doesn't extend to group libraries for some reason.

When I run the runImport command from the console like so:

app.plugins.getPlugin('obsidian-zotero-desktop-connector').runImport('Literature note', "@Bell.etal2019SpatialHabitatVariation")

I get the following errors:

plugin:obsidian-zote…esktop-connector:98 Error: not found: Bell.etal2019SpatialHabitatVariation
    at rr (plugin:obsidian-zote…p-connector:98:8508)
    at async Sp (plugin:obsidian-zote…-connector:112:1645)
    at async Nc.runImport (plugin:obsidian-zote…onnector:118:314342)
rr  @   plugin:obsidian-zote…esktop-connector:98
await in rr (async)     
Sp  @   plugin:obsidian-zote…sktop-connector:112
runImport   @   plugin:obsidian-zote…sktop-connector:118
(anonymous) @   VM418:1
plugin:obsidian-zote…sktop-connector:112 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'length')
    at Sp (plugin:obsidian-zote…-connector:112:1704)
    at async Nc.runImport (plugin:obsidian-zote…onnector:118:314342)
Sp  @   plugin:obsidian-zote…sktop-connector:112
await in Sp (async)     
(anonymous) @   VM418:1

The citekey was copied from Zotero's item pane of an item in a group library, so that shouldn't be the issue.

image

Demo: Item imported via command palette, but fails via runImport

https://github.com/mgmeyers/obsidian-zotero-integration/assets/33608083/f133cdca-62fb-4907-88ff-a33263cdb77b

mgmeyers commented 11 months ago

So, one annoying thing about zotero/BBT is that you have to explicitly specify which library you want to import from. runImport actually supports a 3rd parameter which is the library id, which is 1 by default (My Library). The function signature looks like this: runImport(name: string, citekey: string, library: number = 1). I'll have to think on this to see if there's a user friendly way of selecting a library

FeralFlora commented 8 months ago

So, one annoying thing about zotero/BBT is that you have to explicitly specify which library you want to import from. runImport actually supports a 3rd parameter which is the library id, which is 1 by default (My Library). The function signature looks like this: runImport(name: string, citekey: string, library: number = 1). I'll have to think on this to see if there's a user friendly way of selecting a library

Hey @mgmeyers, thanks for the answer! That does clear up some things, but it's still unclear to me if there's a reliable way for users to select a particular group library. Like, are the numbers in the same order as in the Zotero UI? Actually, I did some tests in the Zotero console, and it appears that the numbers are in the same order as the order in the Zotero UI.

You can check it using: Zotero.Libraries.getName(NUMBER), and inputting a number. 1 is of course "My Library", 2 is the first one below My Library and so on.