Detailed Use of the JavaScript Library

The following methods are available on the object returned by bomgarState() (the object called allChangesObservable in the example in Basic Use of the JavaScript Library). These methods allow you to subscribe to more focused changes based on table names and change types. Some developers may find these more convenient to use than registering a single callback function for all tables and change types using subscribe() as seen with the basic usage.

.changesForTable(tableName)

Calling this function subscribes only to model changes for the given table name.

Arguments

tableName ( String ): The name of a table you requested from bomgarState() using the tables option.

Returns

( Observable<ChangeObject> ): An observable of changes to the given table. Change objects have "name" and "data" properties:

{

"name": "<change type>", // "insert", "update", or "delete"

"data": {

"<id>": {

// Varies depending on table and change type

},

// Other rows

}

}

Example

// Get all the change messages for the 'representative' table in one subscription

allChangesObservable.changesForTable('representative')

.subscribe(function onRepTableChange(repChangeObject) {

// 'repChangeObject.name' contains the change name 'insert', 'update', or 'delete'

// 'repChangeObject.data' contains the data related to the change from changeObject[change][tableName] int he '.subscribe()' example

switch (repChangeObject.name) {

case 'insert':

// Use 'repChangeObject.data' to perform an insert

break;

case 'update':

// Use 'repChangeObject.data' to perform an update

break;

case 'delete':

// Use 'repChangeObject.data' to perform a delete

break;

}

});

.tableInserts(tableName)

Calling this function subscribes only to inserts for the given table name.

Arguments

tableName ( String ): The name of a table you requested from bomgarState() using the tables option.

Returns

( Observable<InsertObject> ): An observable of inserts into the given table. Insert objects contain one or more property names that are IDs for the table row and also contain property values that are objects containing the data to insert.

{

"<id>": {

// Varies depending on table

},

// Other inserts

}

Example

// Create a subscription for inserts into the 'customer_client' table

allChangesObservable.tableInserts('customer_client')

.subscribe(function onCustomerClientInsert(insertObject) {

// Insert rows

});

.tableUpdates(tableName)

Calling this function subscribes only to updates for the given table name.

Arguments

tableName ( String ): The name of a table you requested from bomgarState() using the tables option.

Returns

( Observable<UpdateObject> ): An observable of updates for the given table. Update objects contain one or more property names that are IDs for the table row and also contain property values that are objects containing the data to update.

{

"<id>": {

// Varies depending on table

},

// Other updates

}

Example

// Create a subscription for updates to the 'customer_client' table

allChangesObservable.tableUpdates('customer_client')

.subscribe(function onCustomerClientUpdate(updateObject) {

// Update rows

});

.tableDeletions(tableName)

Calling this function subscribes only to deletions for the given table name.

Arguments

tableName ( String ): The name of a table you requested from bomgarState() using the tables option.

Returns

( Observable<Deletion[]> ): An observable of deletions for the given table. Deletion objects are arrays of row IDs:

[

"<id>",

// Other IDs

]

Example

// Createa subscription for deletions from the 'customer_client' table

allChangesObservable.tableDeletions('customer_client')

.subscribe(function onCustomerClientDeletion(deletionObject) {

// Delete rows

});

.truncations()

Calling this function subscribes to notifications that all tables should be truncated.

Bomgar is the leader in Secure Access solutions that empower businesses. Bomgar's leading remote support, privileged access, and identity management solutions help support and security professionals improve productivity and security by enabling secure, controlled connections to any system or device, anywhere in the world. More than 10,000 organizations across 80 countries use Bomgar to deliver superior support services and reduce threats to valuable data and systems.