package com.servicemax.myapp.event_handler
import com.servicemax.core.event_handler.TemplateOperationEventHandler
class EventHandlerSubclass extends TemplateOperationEventHandler {
public Object realExecute(Map<String,Object>params) {
}
}
package com.servicemax.myapp.event_handler
import com.servicemax.core.event_handler.TemplateOperationEventHandler
import com.servicemax.core.Database
class EventHandlerSubclass extends TemplateOperationEventHandler {
static def eventHandlerData = [];
public static void reset() {
eventHandlerData = [];
}
public Object realExecute(Map<String,Object>params) {
affectedMaxObject.io_name = "a new name"
Database.upsert(affectedMaxObject)
logger.info("name changed by event handler")
}
}
|
|
The affectedMaxObject variable specifies the record affected by a Template Operation, for example, the deleted record in a Delete operation. The logger variable grants access to a logger.
|
Max.executeInTransaction {
def recordId = affectedMaxObject.io_uuid
def record = Database.querySingleResult("select * from <object's full identifier> where io_uuid = :id", [id : recordId])
...
}
|
|
Before event handlers are preferable, because they run during the same transaction in which the associated event occurs, so all changes are executed automatically. Otherwise, data inconsistencies can be introduced in cases where errors are present in the event handler. After event handlers should be used only in special cases that require the use of a different transaction.
|