Skip to content

Unconditional Delivery Listeners

Description

This operation allows registering an event listener for a specific data table. The listener is triggered every time the upsert operation is invoked and an object is updated or inserted in the data table. The event listener will receive only those objects which are being upserted in the database.

Method

rtHandlers.addUpsertListener<T = object>(callback: (obj: T) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;

where:

Argument                Description
callback Represents an object returned by the event listener after the upsert operation takes place in the data table. The object contains properties and updated values as presented in the data table.

Return Value

None.

Example

The example below registers a new event listener in the data table. The listener is triggered every time the upsert operation is invoked and an object is updated or inserted in the data table

const dataStore = Backendless.Data.of('Person')
const rtHandlers = dataStore.rt()

rtHandlers.addUpsertListener(data => {
  console.log(data)
}, error => {
  console.error(error)
})

Codeless Reference

rt_database_upsert_conditional_delivery_1

where:

Argument                Description
id Unique identifier of the new event listener.
table name The name of the data table where a conditional event listener must be registered.
where clause Optional parameter. Sets the condition for an event listener which gets triggered every time the condition is met when the upsert operation is invoked for a specific data table. For more information about the where clause syntax, see the Condition Syntax section of the guide.
object When an objects is upserted and an event listener gets triggered, the modified object that triggered the listener gets saved to this variable (object) and then it can be used for other Codeless operations.

This operation does not return a value. However, every time an event listener is triggered, the operation writes the object that was upserted in the data table to the object variable. You can use the contents of the object variable in other operations.

The example below registers a new event listener for the "Person" data table. The listener is triggered when an object is upserted(updated or inserted) in the data table.

When the event listener is triggered, the Codeless logic below executes a custom block of code; First the following sentence is printed: "Upsert operation has triggered the listener.", then the value of the property objectId is retrieved from the object variable and also gets printed.

rt_database_upsert_unconditional_delivery_1