I found rollback() function here: https://final-docs.campaign.adobe.com/doc/AC/en/jsapi/m-DBEngine-rollback.html however, I'm not sure how to use it or if I can use it.
If there'll be a sample code, it would greatly help. Thank you so much.
by my opinion xtk.session.Write() is final statement (after execution an automatically COMMIT is done).
It is best option to open one ticket towards Adobe Support to clarify usage of rollback().
You might try to create a procedure on DB level (basic Oracle example below) and then adapt your web service to invoke procedure and then everything will be done by your database.
CREATE PROCEDURE foo (x NUMBER) IS
-- Do some inserts here.
INSERT INTO bar VALUES (x);
-- Sometimes there might be an error.
IF x = 3 THEN
WHEN OTHERS THEN
-- Rollback everything which was made after `SAVEPOINT update_bar`
ROLLBACK TO update_bar;
you may use dbEngine class to work with sql queries from JS.
var dbEngine = instance.engine
dbEngine.exec("UPDATE your_table SET column = 1 WHERE 1=1")
Therefore, it is possible to use something like dbEngine.rollback() but not after the code above because commit is done automatically. You have to write procedure in order to use commit or rollback after transaction.
Thank you for your response.
I'm using xtk.session.Write() to insert/update a schema in a jssp.
(Still new in Campaign and so far I have been using this function when doing insert/update/delete.)
A bit of background: This jssp file is being called by AEM as a webservice.
It has a series of processes which involves search of schema and insert/update record.
In case there's an error thrown, I would like to rollback all the insert/update made before the error is encountered.
Is it possible to do a rollback after that?