Child pages
  • Table Events

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

Throwing an exception in the event method will result in a Servoy Exception with a SAVE FAILED error code, which may be handled in the solution's onError event handler.

 

Example

This is an example of an onRecordDelete handler for an invoices table. The data rule is that posted invoices will never be deleted by the application.

...

The next three events occur just prior to the operation intended to be done on the foundset. The event handler has the opportunity to prevent the operation to take place. This is an ideal place to set fail-safe data rules.

  • onFoundSetRecordCreate - occurs prior to a new record being created in the foundset
  • onFoundSetFind - occurs prior to the foundset going into find mode
  • onFoundSetSearch - occurs prior to executing a search on the foundset

...

Parameters

The onFoundSetSearch method event receives two parameters:

  • clearLastResults - Boolean which tells whether or not to clear previous search
  • reduceSearch -  Boolean which tells to reduce (true) or extend (false) previous search results

...

Example

This is an example of an onFoundSetFind handle handler. The data rule is that the foundset doesn't go into find mode if there are no records in the table.

Code Block
/**
 * Foundset pre-find trigger.
 * When false is returned the foundset will not go into find mode.
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"9FE55B79-E5D1-4B7D-82CD-D0E8CF6B6725"}
 */
function onFoundSetFind() {
    if(record_count == 0) // record_count is an aggregation defined for the table, which counts the records
        return false;
    return true;
}

The last three events occur immediately following the operation executed on the foundset.

  • afterFoundSetRecordCreate - occurs subsequent to the creation of a new record
  • afterFoundSetFind - occurs subsequent to entering find mode
  • afterFoundSetSearch - occurs subsequent to performing the search for a foundset

Parameters

The afterFoundSetRecordCreate event receives parmeter JSRecord which is the record object that was recently crated.

Example

This is an example of an afterFoundSetRecordCreate handler for book_text table. The data rule is that every new record added to the foundset will have a predefined text on the comment_text column.

Code Block
/**
 * Record after-create trigger.
 *
 * @param {JSRecord<db:/example_data/book_text>} record record that is created
 *
 * @properties={typeid:24,uuid:"CCDA9A02-7E4D-4A82-9815-B030BBDB1ED0"}
 */
function afterFoundSetRecordCreate(record) {
    record.comment_text = "Some predefined comment.\n"
}