Please share an example of using context.createTransaction() in frontend and for doing the same in Action code
Hi Pranit,
To execute a series of database-operations from front-end code you should use the Transaction-API as you noted. Hereās an example:
var tx = context.createTransaction();
tx.addOperation({
op: "ADD",
records: [rec1,rec2]
});
tx.addOperation({
op: 'UPD',
records: [rec3,rec4]
});
tx.commit().then(function(res) {
alert("Success");
});
You can create, update and delete records in an atomic fashion this way (the operations are named āADDā,āUPDā and āDELā). We are currently putting a lot of errort into improving our documentation and will be detailing this over there shortly.
For handling transactions inside an action there is already an example here (scroll down to the section labeled āWorking with the databaseā:
https://docs.appivo.com/articles/scripts/
Thanks,
/Johan/
2 Likes