A Note item.title = undefined? (URI export translator)

edited April 28, 2019
Hello I am adapting the "Select item" translator with success so I have the title + URI of an item. It works with every item with a link but whenever I try to do it with a note the item title shown is "undefined".

Example:

(with items with links, like articles)
1.1 Alcohol intake and pregnancy - UpToDate zotero://select/items/6_6CXJ8EYV
1.0 Substance use by pregnant women - UpToDate zotero://select/items/6_FRQCETT2

(with notes)
undefined zotero://select/items/6_JL9UALAT

Link to the original translator :
https://raw.githubusercontent.com/Zotero-ODF-Scan/zotero-odf-scan/master/attic/Zotero Select Item.js


Question:

What is the equivalent of "item.title" for a note ? if it could give me even the first 10 words of a note I think it should be fine. If it is too much work to learn how to make it work with that translator I am fine having 2 version of the same translator.

Details:

This is important for me since I use a standalone note as the main note of a topic in zotero, with many URIs like the ones above to link to the many child note each article has. It makes Zotero really useful for me. I using a workaround with excel to get the title of a note and concatenate it with the URI, but there must be an easier way,

I read as much as I could but I couldn't find a answer. I don't know how to code but I can figure stuff out, only I don't have much free time to do so.

Any advice is appreciated!


  • Does item.noteTitle work better on the notes?
  • Sadly it did not. Here is how my working version of the original translator looks like.

    Even when I tried writing item.noteTitle in different places it didn't work. It just made even item types with links to be set as "undefined". Thank you for your prompt answer though.

    function doExport() {
    var item;
    while(item = Zotero.nextItem()) {
    Zotero.write(item.title+" "+"zotero://select/items/");
    var library_id = item.libraryID ? item.libraryID : 0;
    Zotero.write(library_id+"_"+item.key+"\n");
    }
    }
  • edited April 28, 2019
    Notes don't have a title. What you see in Zotero overview as the title is effectively just the first line of the note body; the note body is available in item.note.
  • If you want the first 10 words, this should sort of work:

    item.note.replace(/<[^>]*>/g, '').replace(/\n/g, ' ').split(/\s+/).slice(0,10).join(' ')

  • Thank you so much! it works quite well for my immediate needs!

    -Using it conditionally?
    For the long term: would you have any advice to share about where should I look up to learn how use that script you suggested conditionally?

    So that I can use item.title for most items and that script for notes. Because when I used that script you shared with that translator it displays: "an error occurred when trying to export the selected file" when I use it on non-note types of items.


    -Why in Word the AMA bibliography of a note gives the note title?
    I am still confused about why in Word when I cite notes in some styles like AMA it returns the title of a note just fine but when I try to generate a bibliography in Zotero or export with quick copy with that style it displays the error of "The item you selected has no references". But oh well...
  • edited April 29, 2019
    You could use something like
    const title = item.itemType === 'note' ?  item.note.replace(/<[^>]*>/g, '').replace(/\n/g, ' ').split(/\s+/).slice(0,10).join(' ') : item.title
    Where to go look up how to use these things: any basic tutorial on Javascript. If you want to do Zotero translators, you will have to get comfortable doing javascript. The object structure isn't documented to my knowledge so I just inspect it by dumping it within the translator.

    As to how such titles show up in the bibliography - no idea. Somewhere between zotero and the citation processor, someone decides to create a title from the notes. But it seems unlikely you'll be able to use this to generate titles.
Sign In or Register to comment.