Related Items in javascript export

73 views
Skip to first unread message

jd...@jd4x4.net

unread,
Mar 27, 2014, 3:22:07 PM3/27/14
to zoter...@googlegroups.com
Are Related Items exposed for access in javascript Export translators? If so, can someone point me to the correct field syntax either by documentation or (better) example?

Thanks. My head is spinning right now and this is the last bit I need for my export translator.

Sebastian Karcher

unread,
Mar 27, 2014, 4:45:36 PM3/27/14
to zoter...@googlegroups.com
item.related is an array containing all the (locally unique but not
preserved during sync) itemIDs of related items. I don't think there is
currently an export translator using that.
The code depends on what you want, but it would look something like
for (var i=0; i<item.related.length; i++){
//here you'd do whatever you need to with item.related[i]
> --
> You received this mesage 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
> <mailto:zotero-dev+...@googlegroups.com>.
> To post to this group, send email to zoter...@googlegroups.com
> <mailto:zoter...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/zotero-dev.
> For more options, visit https://groups.google.com/d/optout.

JD4x4

unread,
Mar 27, 2014, 9:19:39 PM3/27/14
to zoter...@googlegroups.com
adamsmith to the rescue, yet again. Thanks.

Well, it works but it's not returning what I expected.. I was hoping it would return the zoteroID of the related item but it's returning a decimal value. :-(

I built it like this:
        if(item.related && item.related.length) {
            var relatedString = "";
for(var i in item.related) {
  var relate = item.related[i];
               relatedString += "Related: " + relate + "\r";
            }
   Zotero.write(relatedString + "\r");
        }

This code was re-purposed from the code I used for iterating tags, stolen from a translator that I can't remember the name of now. 

I wish I had a schema or something for what's exposed, under what names. Between not knowing javascript much at all, and not knowing if I'm looking for items or arrays, I'm loosing my already thinning hair.

Sebastian Karcher

unread,
Mar 27, 2014, 10:08:33 PM3/27/14
to zoter...@googlegroups.com
yeah, unfortunately I don't think there is a way to the the item key
from the itemID in a translator - and the itemID is the only thing that
"related" contains for an item.
> --
> You received this message because you are subscribed to the Google

JD4x4

unread,
Mar 27, 2014, 10:38:43 PM3/27/14
to zoter...@googlegroups.com
Dang. Story of my life.
Well, without your help I never would have gotten this far. And What I wound up with is a MAJOR help in automating my process, even without the 'related' icing on my cake.

I owe you BIG time. 

Frank Bennett

unread,
Mar 28, 2014, 12:15:06 AM3/28/14
to zoter...@googlegroups.com
On Fri, Mar 28, 2014 at 11:08 AM, Sebastian Karcher <bst...@gmx.de> wrote:
> yeah, unfortunately I don't think there is a way to the the item key
> from the itemID in a translator - and the itemID is the only thing that
> "related" contains for an item.

I may be missing something, but here goes.

If you have access to the items in the translator, they carry the keys
themselves, so you should be able to fetch the related IDs, then
iterate over the items and replace or supplement the IDs with the
keys.
> To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
> To post to this group, send email to zoter...@googlegroups.com.

JD4x4

unread,
Mar 28, 2014, 12:49:40 AM3/28/14
to zoter...@googlegroups.com
I'm a noob at all of this but I've worked with sgml/xml before so that's my perspective, without understanding zotero..
 but are you saying that the parent zotero ID (key) of the related item is an attribute (or child?) of the related ID that I'm getting returned from the code?


(It's late, and I'm not sure I even understand what I just wrote, lol.)

On Friday, March 28, 2014 12:15:06 AM UTC-4, Frank Bennett wrote:

Frank Bennett

unread,
Mar 28, 2014, 1:07:12 AM3/28/14
to zoter...@googlegroups.com
On Fri, Mar 28, 2014 at 1:49 PM, JD4x4 <jd...@jd4x4.net> wrote:
> I'm a noob at all of this but I've worked with sgml/xml before so that's my
> perspective, without understanding zotero..
> but are you saying that the parent zotero ID (key) of the related item is
> an attribute (or child?) of the related ID that I'm getting returned from
> the code?

No, the related ID is just a number. Reflecting on the problem, I
think my suggestion is off-base. You are presumably exporting one or
more items IDs in their "related" segments that point at items that
are not in the export. In that case, there is no simple way to obtain
the items from Zotero, and without the items, you can't get at their
key strings.

So I *was* missing something. :/

Frank

JD4x4

unread,
Mar 28, 2014, 7:17:43 AM3/28/14
to zoter...@googlegroups.com
Well thanks anyway. Yes, I am getting the relatedIDs via the other records. It's a shame really that there is no way to use this. I'm guessing it's some type of database index that's useful only 'internally' but it seems without benefit to even have it available to the translators if you can't get back to the parent key. 

Doesn't sound like what I'm trying to do can be accomplished with the web API either.. or can it? 


Emiliano Heyns

unread,
May 13, 2014, 9:25:31 AM5/13/14
to zoter...@googlegroups.com
On Friday, March 28, 2014 12:17:43 PM UTC+1, JD4x4 wrote:
Well thanks anyway. Yes, I am getting the relatedIDs via the other records. It's a shame really that there is no way to use this. I'm guessing it's some type of database index that's useful only 'internally' but it seems without benefit to even have it available to the translators if you can't get back to the parent key. 

Doesn't sound like what I'm trying to do can be accomplished with the web API either.. or can it? 


The items in the export each have an 'itemID'; the 'related' field is an array of those IDs, so that's easy to resolve. The problem you're hitting is probably that the collection of items your translator is presented is limited to those the user has selected -- if the related items are not in that set, there's no way for you to retrieve them.

Dan Stillman

unread,
May 13, 2014, 2:52:41 PM5/13/14
to zoter...@googlegroups.com
On 3/28/14, 7:17 AM, JD4x4 wrote:
Doesn't sound like what I'm trying to do can be accomplished with the web API either.. or can it?

Well, you can get related items via the API, if that's what you're asking. You need to pass the "Zotero-API-Version: 2" header in order to get the 'relations' property in the item JSON (?content=json), and then the URIs for related items will be under the 'dc:relation' predicate.
Reply all
Reply to author
Forward
0 new messages