Export collection / subcollection names

Dear Zotero community,

I followed each step from this thread and came up with a nice-clean-customized CSV, however I was wondering if there was a way to keep the collection's / subcolletion's names in a column?

Aurimas/Philipp if you're reading this, please know I am deeply thankful for your clear code!
  • I don't think that's feasible with reasonable effort, no, so I wouldn't expect it to happen. (It's not impossible, just quite involved for a format that I don't think anyone considers a major priority).
  • Dear Adam, thank you so much for your quick response, unfortunately I need to do this, and if you could give me any clues on how to achieve this, I would be very thankful

    [A way to automatically add the name of my collections as tags would also work for me]
  • I guess that there are some other export translator which are dealing with that, e.g. Zotero RDF seems to handle that somehow. However, for such modification you have to be familiar with JavaScript programming language.

    You could export collection-by-collection if there are not so many collections overall.
  • Hi,

    I am trying to write a translator that relates to this request to help me classify papers using collections and subcollections. I am modifying the csv translator and used nextCollection() function as indicated here

    https://www.zotero.org/support/dev/translators/coding#export_translators

    However the sequence of collections I get this way is flat (i.e. I do not get the children relationship between collections). I have been trying to use the functions Zotero.getCollections(collID) to get subcollections as indicated here

    https://www.zotero.org/support/dev/client_coding/javascript_api#zotero_collection_operations

    but the debug says

    [JavaScript Error: "Zotero.getCollections is not a function" {file: "/home/lluj/.mozilla/firefox/mou1wg2i.default/zotero/translators/CSV-review.js" line: 185}]

    and when I try to ask Zotero.debug(collection.hasChildCollections), I get

    (3)(+0000001): ===>undefined<=== (undefined)

    Although I know the collection has subcollections

    Do I need to add a line to import the API? Note that I added in the translator config the line

    "configOptions": {"getCollections": true},

    Related to this question, is there a way to get (in an exporter tranlator) the list of all the collections a bibliographic item belongs to? the way the ctrl or alt key works?

    Thanks for Zotero it is amazing!
  • (Short answer:) Try to look at the Zotero RDF translator for inspiration: https://github.com/zotero/translators/blob/master/Zotero RDF.js
  • edited August 25, 2016
    (Long answer): The function `Zotero.getCollections` is part of Zotero and can be used in the JavaScript API, i.e. for creating extensions based on Zotero, but you cannot use this function in translator code. If you want to look at the wiki (which might be sometimes outdated), then start here https://www.zotero.org/support/dev/translators instead.

    A possible way to go trough all collections is shown in the Zotero RDF export translator. It will start at the top collections, go to the childrens which might be items or collections, and recursively continue on the collections:

    while(collection = Zotero.nextCollection()) {
    generateCollection(collection);
    }

    function generateCollection(collection) {
    var id = collection.id;//TODO do something with it
    var name = collection.name//TODO do something with it

    var children = collection.children ? collection.children : collection.descendents;
    if(!children) return;
    for (var i=0; i<children.length; i++) {
    var child = children[i];
    if(child.type == "collection") {
    //TODO do something here
    generateCollection(child);
    } else {
    //TODO do something here
    }
    }

  • very nice answer! and much quicker than my reading... I was scared by the RDF stuff at the top but once I scrolled down I found something in the generateCollection() function. I'll let you know. many thanks!
  • oh I did not see the long one...
  • I am looking forward to hear about your progress. Maybe, it is even interesting for the official CSV export translator.
  • I hacked a solution and it seems to work. It is completely ad-hoc to my purpose (categorize papers according to multiple categories using a first collection layer of categories and a subcollection layer of values).

    The way I did it was to go through the subcollections while writing the header, creating a data structure of categories/values/items as below and adding the categories columns at the end.

    [
    "0": [object Object] {
    "name": "modality"
    "values": [
    "0": [object Object] {
    "name": "webcam"
    "items": [
    "0": "Q9RBXF5H"
    ]
    }
    "1": [object Object] {
    "name": "IR"
    "items": [
    "0": "M5AC4PE8"
    "1": "4GJG3KHX"
    ]
    }
    ]
    }
    "1": [object Object] {
    "name": "method"
    "values": [
    "0": [object Object] {
    "name": "user study"
    "items": [
    "0": "Q9RBXF5H"
    "1": "4GJG3KHX"
    ]
    }
    "1": [object Object] {
    "name": "Survey"
    "items": [
    "0": "M5AC4PE8"
    ]
    }
    ]
    }
    ]
    then the doExport function adds at the end of the line the appropriate (category) value if the item currently processed is in the list of items (which have the value x for the category y)

    (please excuse the code style I am not JS-able)


    for (var i=0; i<categories.length; i++) {

    var found = false;
    var values = categories[i].values;
    for (var j=0; j<values.length; j++) {
    var value = values[j];

    // use keys to compare
    if (include(value.items,item.key)) {
    found = true;
    line += fieldDelimiter + fieldWrapperCharacter + value.name + fieldWrapperCharacter;
    if (!multipleValues) continue;
    }
    }

    if (!found) {
    line += fieldDelimiter + fieldWrapperCharacter + 'undefined' + fieldWrapperCharacter;
    }
    }


    I could attache an RDF file + exporter + csv output but do really know how to do it on this forum. Do you think it is needed?

    Regarding including this in the official CSV, we should discuss the way to make it generic. If you are interested I am glad to help to the limit of my knowledge... Anyway thank you very much for the amazing support! I was considering purchasing storage, I will do it gladly as a support.
  • Reading again the documentation on export translator I realize that there is a broken link at the bottom that led me to think I could use the Javascript API.

    https://www.zotero.org/support/dev/translators/coding#export_translators

    Maybe the excerpt you quoted could fit nicely in this part of the doc.
  • You can share your code for example in a gist, i.e. https://gist.github.com/ which will help people having the same need. This would also allow us, to look closer at your code.

    I corrected the dead link in the wiki. Thank you.
  • I am interested to know if it is possible to export a collection's name or its key
    somehow, in order to be able to use it with zotero select as mentioned here
    https://forums.zotero.org/discussion/73893/zotero-select-for-collections#latest

    I couldn't understand the code mentioned above in this post nor how to obtain that metadata via an export translator.

    Because from what I understood the discussion in this post suggest is not but the documentation suggest otherwise.
    https://www.zotero.org/support/dev/translators/coding#export_translators



  • Hello.
    First, thanks for Zotero, it's definitely essential to my studies.
    @zuphilip I'm using Zotero 6.0.4 and noticed that the CSV exporting tool still not export subcollection item's from a parent collection. In this forum you suggested to add this functionality to the official CSV export translator. Since I don't know programming, I wonder if this is going to happen.
    In the meantime, I'm exporting each subcollections and merging manually the CSV files, but ir would be great to have it later Thanks a lot again.
Sign In or Register to comment.