Add After Save Event in Merciglobal Cloud ERP
Overview
The Add After Save event (_add_aftersave
) in Merciglobal Cloud ERP is a versatile event hook that triggers after a new record is successfully inserted into the database. It's a valuable extension point for executing post-insert actions such as logging, sending notifications, or launching workflows.
โ ๏ธ This event is applicable only for form tables.
Function Signature
Define this function in the /libfuncs.php
file:
function _add_aftersave($nNewMasterID = 0) {
// Your custom logic here
}
Note: Replace the prefix with your specific tablename, for example:
function trn_salesinvoice_add_aftersave($nNewMasterID = 0) {
// Custom logic for sales invoice
}
Parameters
-
$nNewMasterID
(int): The unique identifier of the newly inserted record. -
Automatically provided by the system.
- Use it to retrieve or manipulate the inserted record's data.
Use Cases
Use Case | Description |
---|---|
๐ Send Email | Dispatch a confirmation or welcome email post-creation |
๐งพ Generate Reference | Create a reference number using $nNewMasterID |
๐งฎ Update Related Tables | Perform post-insert calculations or updates |
๐๏ธ Log Creation | Insert a log into an audit trail or history table |
๐ Trigger Automation | Launch background jobs or integrations |
Example
A basic example that logs the ID of a newly inserted customer:
function trn_salesinvoice_add_aftersave($nNewMasterID = 0) {
// Log to system error log
error_log("New customer added with ID: $nNewMasterID", 0);
}
Tips for Developers
- Validate
$nNewMasterID
before using it in queries to avoid errors. - Avoid time-consuming operations directly in this function โ consider asynchronous processing.
- Organize logic into helper or service classes for better maintainability and testing.
Summary
๐ Feature | ๐ Description |
---|---|
Event Name | _add_aftersave |
Trigger Time | After a new record is inserted |
Parameter | $nNewMasterID โ ID of the newly added record |
Use Cases | Logging, Notifications, Reference Code, Integrations |
๐ Merciglobal Cloud ERP continues to empower your development with smart, event-driven extensibility. Need assistance? Contact the Merci Developer Support Team! ๐ฌ