Help writing a export translator

edited December 25, 2021
I am writing a translator to export a few item fields in a format that would work with a Dataview plugin in Obsidian. I'm not an expert and can only work from existing examples. I have two problems:

1. I am converting the Date field like this:
var date = "Date:: " + Zotero.Utilities.strToISO(item.date) + "\n";
For items with year/month/day date, I end up with YYYY-MM-DD (this is what I need). But for books I get only YYYY. How do I get from YYYY to YYYY-MM-DD? For example, I need to get from 1996 to 1996-01-01

2. I can only export the first author because I modified the code included here: https://github.com/silentdot/zotero-markdown-translator/releases
But I need to export all authors for each item. Where can I get the code for the loop to get all authors?

Thanks!
  • 1. Since YYYY is a perfectly valid ISO date, that's what Zotero gives you when there's only a year in the date. If you always want -01 added, I'd just do it manually (untested):

    let isodate = ZU.strToISO(item.date);
    if (isodate.length == 4) {
    isodate += "-01-01"
    } else if (isodate.length == 7) {
    isodate += "-01"
    }

    "Date:: " + isodate + "\n";


    Tbc
  • I am converting the Date field like this: var date = “Date::” + Zotero.Utilities.strToISO(item.date) + “”; For items with year/month/day date, I end up with YYYY-MM-DD (this is what I need). But for books I get only YYYY. How do I get from > YYYY to YYYY-MM-DD? For example, I need to get from 1996 to 1996-01-01

    var date = Zotero.Utilities.strToISO(item.date);
    if (date.length) {
    switch (date.split('-').length) {
    case 1:
    date += '-01-01';
    break;
    case 2:
    date += '-01';
    break;
    }

    date = `Date:: ${date}\n`;
    }

    But I need to export all authors for each item. Where can I get the code for the loop to get all authors?

    if (item.creators && item.creators.length) {
    var creators = item.creators.map(creator => creator.lastName || creator.name).join('; ')
    }
    or
    if (item.creators) {
    for (const creator of item.creators) {
    // do something with creator here
    }
    }
  • edited December 25, 2021
    Thank you!!! (both of you)
Sign In or Register to comment.