How can I delete records from Page OnAfterGetRecord ?

Hello Friends,

I have maintain one my own table to store future contract related information in my ‘X’ table. So my requirement is on Page close, record next, previous time generate the data and store in ‘X’ table.
Also, in my case if record already found in ‘X’ table then first deletion is required. Its work fine on page close event, and also record insert process works find in record next, previous time (Page OnAfterGetdata Event). My delete process not work its given error ‘A transaction must be started before changes can be made to the database’

I have also try OnNextRecord event but it’s also not work.

Can you please give me idea, how can I delete records from Page OnAfterGetRecord?

Thanks in advance