Page History
...
This is an example of an onRecordDelete handler for an invoices table. The data rule is that posted invoices will never be deleted by a the application.
Code Block |
---|
/**/**
* Record pre-delete trigger.
* Validate the record to be deleted.
* When false is returned the record will not be deleted in the database.
* When an exception is thrown the record will also not be deleted in the database but it will be added to databaseManager.getFailedRecords(),
* the thrown exception can be retrieved via record.exception.getValue().
*
* @param {JSRecord} record record that will be deleted
* @returns {Boolean} true to allow a delete
* @properties={typeid:24,uuid:"A3F02F99-B899-46BE-9125-66E4189F043F"}
*/
function onRecordDeleteInvoice(record) {
if(record.is_posted)
throw "Cannot delete a posted invoice";
return true;
}
|
...
This is an example of an afterRecordInsert handler for a projects table. The data rule is that a new project record will be linked, via the projects_users table, to the current user.
Code Block |
---|
/**/**
* Record after-insert trigger.
*
* @param {JSRecord} record record that is inserted
*
* @properties={typeid:24,uuid:"92834B20-1CAC-472F-B022-DD97FEFEA792"}
*/
function afterRecordInsert(record) {
if(record.projects_to_projects_users.newRecord()){ // create a link record
record.projects_to_projects_users.user_id = globals.currentUserID; // associate to current user
databaseManager.saveData();
}
}
|
Overview
Content Tools
Activity