Table Event Issue (Do After Insert)

Hi, I am having issues with the Do After Insert table event,

I needed to run a function(logic) to insert some details into another table after an insert to a table; although no error occurred but the details were not inserted (confirm it by running a query on the table). After some trial and error, I observe the function worked on the Do Before Insert event but does not work on the Do After Insert.

I need to use the Do After Insert event. Kindly help with this.

Below is the simplified logic not working on Do After Insert but worked on Do Before Insert

const currentUserKey = five.currentUserKey();

   let userResults = five.executeQuery("INSERT INTO BriefHistory (BriefHistoryKey, AddedBy, Date) Values(?, ?, ?)", 0, five.uuid(),currentUserKey,;
        if (userResults.isOk() === false) {
            return five.createError(userResults);
    return five.success(result);

Hi Jaymeeu,

The Do After Insert event is actually outside of the main transaction, therefore, to make changes to the database (insert, update, delete) you will need to create your own transaction with which you can then commit your work.

You do this by using Five’s inbuilt functions:

  • getDatabaseConnectionByID()
  • startTransaction()
  • commit()

A basic example is as follows:

const db = five.getDatabaseConnectionByID('DatabaseID_GOES_HERE');
const tx = five.startTransaction(db);
five.executeQuery(tx, `UPDATE Customers set Name=?`, 0, 'John Citizen');

You can find more examples in our API documentation:

The only other thing to note, is the ID for your database is on the Database record under the Data menu item, this is the value you need to pass to the getDatabaseConnectionByID(). To find this value:

  1. Click Data in the menu.
  2. Click Databases in the sub-menu.

The value you need is located in the Database ID field.

For additional information please refer to the following links:

Hi Jo-Anne,
Thanks for the feedback, this solve my problem :+1:

1 Like