Skip to content

Getting primary and secondary item types in Zotero

A Chickenfoot script for calculating the primary and secondary Zotero items (which draws upon the code in overlay.js->onLoad():


// based on https://www.zotero.org/trac/browser/extension/tags/1.0.7/chrome/content/zotero/overlay.js#L153

var Zotero = chromeWindow.Zotero;

var itemTypes = Zotero.ItemTypes.getPrimaryTypes();

for(var i = 0; i<itemTypes.length; i++) {
  output (itemTypes[i]['name'] + ":" + itemTypes[i]['id']);
}

var itemTypes = Zotero.ItemTypes.getSecondaryTypes();

for(var i = 0; i<itemTypes.length; i++) {
  output (itemTypes[i]['name'] + ":" + itemTypes[i]['id']);
}

The output of the script is (for Zotero 1.0.7):

book:2
bookSection:3
document:34
journalArticle:4
magazineArticle:5
newspaperArticle:6
artwork:12
audioRecording:26
bill:16
blogPost:23
case:17
computerProgram:32
conferencePaper:33
dictionaryEntry:36
email:21
encyclopediaArticle:35
film:11
forumPost:25
hearing:18
instantMessage:24
interview:10
letter:8
manuscript:9
map:22
patent:19
podcast:31
presentation:27
radioBroadcast:30
report:15
statute:20
thesis:7
tvBroadcast:29
videoRecording:28

When you hit "New Item" button in Zotero, you are given the option of creating a new item of one of a given type:

primary and secondary Zotero item types

Furthermore, you can use Zotero.ItemTypes to map between item types and IDs:

Zotero.ItemTypes.getID('book'); yields 2

and

Zotero.ItemTypes.getName(2); returns book

{ 1 } Comments

  1. yee | December 11, 2008 at 2:52 pm | Permalink

    Dan Stillman sent me the following clarification: "You can also just get all item types with Zotero.ItemTypes.getTypes(), which returns an array of objects with 'id' and 'name' properties. The concept of primary and secondary might very well go away, since the menu might be changed to just show the most recently used types."

    Thanks, Dan!

Post a Comment

You must be logged in to post a comment.