setCollection with javascript api doesn't work

41 views
Skip to first unread message

Jason Friedman

unread,
Sep 12, 2016, 1:43:12 AM9/12/16
to zotero-dev
I posted this originally to the zotero forums, but Dan Stillman suggest I post here instead:

Hi,

I have a perl script that used to work to export (from the command line) either the whole library or a single collection as a bibtex file. While the whole library still works, selecting a single collection does not.

In particular, I run something like this to get just the 3rd collection:
var collections = Zotero.getCollections();
var collection = collections[2];
translatorObj.setCollection(collection,1);

but when I run the translator, it still returns the whole library. This is the whole code (I am testing it using MozRepl):

var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath('/tmp/tmpfile.txt');
var translatorObj = new Zotero.Translate.Export;
var collections = Zotero.getCollections();
var collection = collections[2];
translatorObj.setCollection(collection,1);
translatorObj.setLocation(file);
translatorObj.setTranslator('9cb70025-a888-4a29-a210-93ec52da40d4');
translatorObj.setLibraryID(null);
translatorObj.translate();

Thanks,

Jason

Dan Stillman

unread,
Sep 12, 2016, 7:28:37 AM9/12/16
to zoter...@googlegroups.com
What Zotero version?
--
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 post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.

Jason Friedman

unread,
Sep 12, 2016, 9:21:30 AM9/12/16
to zoter...@googlegroups.com
Version 4.0.29.11 standalone, running on OSX 10.11.6

To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+unsubscribe@googlegroups.com.

To post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.

--
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/5DQx6U0WjYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+unsubscribe@googlegroups.com.

To post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.



--
Jason Friedman, PhD
Senior Lecturer
Department of Physical Therapy
Tel Aviv University

Dan Stillman

unread,
Sep 16, 2016, 6:25:17 PM9/16/16
to zoter...@googlegroups.com
You're calling setLibraryID(), which clears the collection selection and
tells it to export that library. Collections exist in libraries, so the
library is implicit when you use setCollection(). Remove the
setLibraryID() call and you should get what you expect.

- Dan

Jason Friedman

unread,
Sep 17, 2016, 2:36:47 PM9/17/16
to zoter...@googlegroups.com
Thanks - that fixed it.

--
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/5DQx6U0WjYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+unsubscribe@googlegroups.com.
To post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages