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 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!
[A way to automatically add the name of my collections as tags would also work for me]
You could export collection-by-collection if there are not so many collections overall.
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!
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
}
}
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. 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.
https://www.zotero.org/support/dev/translators/coding#export_translators
Maybe the excerpt you quoted could fit nicely in this part of the doc.
I corrected the dead link in the wiki. Thank you.
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
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.