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
Using
So when do
I don't want to end up corrupted the database or encountered any sort of problems later on due to not using
(Also, are there any docs explaining the difference between
Very many thanks
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
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.save()
is meant to be used within a transaction.saveTx()
starts its own transaction and will hang if it's used withinexecuteTransaction()
.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