AutoSerial Generation for Compound Unique Index Field in Merciglobal Cloud ERP¶
This guide explains how to generate an AutoSerial value for a compound unique index field in Merciglobal Cloud ERP. This is particularly useful when your module requires a unique serial number based on multiple fields (i.e., compound keys).
Objective¶
Automatically generate a unique serial number during a record's creation (add operation) when the field is part of a compound unique index.
Where to Apply¶
Apply this logic in the Post Validation script section of the form or module definition.
Example: For book/type
Module¶
Use the following PHP snippet in the Post Validation script of your module:
if (strtoupper($_POST["sys_flag"]) == "ADD") {
scr_varset("srno", generateAutoSerial4UniqueField());
}
Function Breakdown¶
$_POST["sys_flag"]
: Checks the system flag to determine the form operation. We only generate the serial on ADD.generateAutoSerial4UniqueField()
: This built-in function creates a serial number, ensuring it remains unique based on compound keys.scr_varset("srno", ...)
: This assigns the generated serial number to thesrno
variable, which should map to your serial field.
Best Practices¶
- Ensure that
srno
is part of the compound unique index for the table. - You can customize the logic inside
generateAutoSerial4UniqueField()
if needed by overriding or enhancing it in your ERP backend. - Validate that no manual override of
srno
occurs after this assignment during the ADD operation.
Use Cases¶
- Document Numbering (e.g., Invoices, Orders, Book Entries)
- Compound key-based logs or configuration modules
This configuration ensures robust, automated serial number generation, improving data consistency and reducing manual errors in compound key scenarios. Perfect for modules requiring strict uniqueness across multiple fields.