Updating Item Types with JavaScript -> partially works

edited yesterday at 5:16pm
Hi,

I created a short JS script to update selected items' Item Type property :

// Update Item Type on selected items in Zotero Pane
var items = Zotero.getActiveZoteroPane().getSelectedItems();
items.map(i => i.setField("itemTypeID", 13)) // Set to dictionaryEntry

As far as the Zotero Pane is concerned, the script works as intended. Item icons and item types are updated correctly.

But the following two things don't work properly :

1) Items listed in Saved Search or Saved Query still display as previous item type.
2) Items listed on zotero.org/user/library ... still display as previous item type.

This doesn't happen on manual update of item types.

When looking at the updated items' JS objects, I found the following two properties :

items[0]._previousData.itemType // returns "webpage"
items[0]._previousData.itemTypeID // returns 40, the itemTypeID for webpage

It seems to be that data that is used to generate the web library on Zotero.org, as well as the advanced search results in Zotero.

After some research, I tried a more specific API method :

items[0].setType(Zotero.ItemTypes.getID('dictionaryEntry'));
OR
items[0].setType(13);

I get the same results, both the saved advanced search results as well as the Zotero.org library seem to feed from :

items[0]._previousData.itemType // returns "webpage"
items[0]._previousData.itemTypeID // returns 40, the itemTypeID for webpage

Note that when we change an itemType manually, the above two fields return 'undefined' and both the advanced research results as well as Zotero.org/library are displayed correctly with the right icon and itemType name.

Is there something I'm doing wrong, or if the "offending" previousData object should be updated by setField() and setType() should update the previousData to undefined like a manual query does?

Thanks in advance.

Sign In or Register to comment.