single field author

After some trial and error, I found out that adding an author to a new zotero object, could be done like this:

newItem.creators[0].creatorType = "author";
newItem.creators[0].firstName = "John";
newItem.creators[0].lastName = "Smith";

But how do you add a single field author? i.e. an organization.

I've been trying to find some documentation on how to make a new translator, but I can't locate any that's not outdated.

It would be a great help. I would be especially grateful for an overview of the Zotero object, and a more extensive explanation of the Zotero utilities than this one: https://www.zotero.org/support/dev/translators/coding#web_translators
  • edited December 8, 2015
    newItem.creators[0].fieldMode = 1;

    Though it's better to push into the creator array.

    newItem.creators.push({lastName: "Smith", creatorType: "author", fieldMode: 1})

    or to use the ZU.cleanAuthor utility:
    newItem.creators.push(ZU.cleanAuthor("Smith", "author", true))


    The one you link to is the only up-to-date documentation there is. I also recommend just reading/checking existing translators as a good way to learn. Look for ones that have been updated relatively recently.

    edit: fixed after fbennett's comment below.
  • It should look something like this:
    newItem.creators.push({
    lastName: "Adam Smith Inc.",
    creatorType: "author",
    fieldMode: 1
    })

    The firstName field should be blank (if it has a value, it will either be ignored, or throw an error). As far as I can tell, cleanAuthor() only supports two-field names.
  • d'oh, of course -- firstName should obviously be blank, thanks fbennett.

    I thought if you force comma=true on an author without comma, you'll get single field with cleanAuthor, but I didn't actually try this.
    If you don't, maybe you should?
  • I haven't tested it, but from the code the useComma option seems meant to parse "lastName, firstName", while without it the parser expects "firstName lastName". If there is no comma in the string, it will leave the lastName field blank. (I'm not sure whether fieldMode is set to 1 by the translator in the latter case, but the useComma toggle doesn't have the effect of forcing single-field mode.)
  • Thanks for helping again, adamsmith and fbennet.

    If it wasn't for you (and other helpful people in these forums), I would still be stuck in CSL-script, and I would never have ventured into writing a translator.

    You are quick to answer, and your responses are attentive and helpful. And I just want to say, that I really appreciate it.
Sign In or Register to comment.