Javascript API: setField() saves without calling save(), so when save()/saveTx() needed?

Hi,

I'm writing some Javascript to clean some of the data fields.

I'm currently just iterating the selected items using Zotero.getActiveZoteroPane().getSelectedItems(). I use setField to update the item.

Using setField seems to write changes to the database without any call to item.save() or item.saveTx() (I'm doing this in synchronous mode).

So when do item.save() or item.saveTx() have to be used?

I don't want to end up corrupted the database or encountered any sort of problems later on due to not using item.save() or item.saveTx() properly.

(Also, are there any docs explaining the difference between item.save() and item.saveTx()? Is the latter only to be used with executeTransaction? And if so, why do some of the examples on https://www.zotero.org/support/dev/client_coding/javascript_api have save() being called within the scope of executeTransaction()?)

Very many thanks
  • Okay, so to answer my own question:

    If you don't call save(), the changes aren't written to disk and so don't persist.

    So without save() it may look like things have changed--the main list and item will show the item as updated, this change won't be written out.
  • (Best to post development questions to zotero-dev. We try to keep technical discussions there.)
    Also, are there any docs explaining the difference between item.save() and item.saveTx()? Is the latter only to be used with executeTransaction?
    Other way around. save() is meant to be used within a transaction. saveTx() starts its own transaction and will hang if it's used within executeTransaction(). save() outside of a transaction will start a transaction for you but will log a warning if a transaction isn't open, because it runs the risk of doing the save within an unrelated transaction.

    Explained here: https://github.com/zotero/zotero/issues/711
Sign In or Register to comment.