Accessing data from a custom event

I am trying to setup a custom event handler.

Ultimately I want to have a column that contains a count of related objects. I will use an event handler on add relation / delete relation / delete object to maintain the counter.

I am not able to get any Data query to run within any event handler though. So I setup this below as a test:

Backendless.ServerCode.Persistence.beforeUpdate('posts', async function(req) {
  //add your code here
  console.log("HERE 1")
  Backendless.Data.of( "posts" ).find()
    .then( function( result ) {
    .catch( function( error ) {
  console.log("HERE 2")

This is just a quick experiment to see where I am going wrong.
When I PUT an update the posts table I see HERE 1 and HERE 2 in the log, but I never see any result of the Data call.

Is there anything I am doing wrong here?

(I realise this is not the end result of what I need, I just want to find out why I can’t run the Data query)

Hello @Tony_Goodchild

try to add await

await Backendless.Data.of( "posts" ).find()

Regards, Vlad

Awesome, thanks so much!