AutoSerial Generation for Compound Unique Index Field in Merciglobal Cloud ERP
Overview
This guide provides a comprehensive explanation for generating an AutoSerial value for compound unique index fields in Merciglobal Cloud ERP. This functionality is crucial for modules where a unique identifier must be created based on multiple field valuesβcommonly referred to as compound keys or composite keys.
Objective
To automatically generate a unique serial number during the creation of a record (i.e., during the ADD operation), specifically when the target field is part of a compound unique index.
Implementation Point
Integrate the AutoSerial logic in the Post Validation script section of your form or module definition.
Example Use Case: book/type
Module
To implement AutoSerial generation in the book/type
module, insert the following PHP code into the Post Validation script:
if (strtoupper($_POST["sys_flag"]) == "ADD") {
scr_varset("srno", generateAutoSerial4UniqueField());
}
Code Explanation
$_POST["sys_flag"]
: Checks the operation type. The AutoSerial is generated only during ADD operations.generateAutoSerial4UniqueField()
: Invokes the built-in function that generates a serial number ensuring uniqueness based on the compound key.scr_varset("srno", ...)
: Assigns the generated serial number to thesrno
field, which must be part of the compound unique index.
Best Practices
- Ensure the
srno
field is a member of the compound unique index in your database schema. - If needed, customize or override the logic inside
generateAutoSerial4UniqueField()
through backend scripting in Merciglobal Cloud ERP. - Prevent any manual overrides of
srno
after its assignment during the ADD operation to maintain data integrity.
Practical Applications
This setup is ideal for:
- Document Numbering: Automatic generation of invoice numbers, order numbers, or book entries.
- Compound Key-Based Modules: Logs or configurations that require unique keys formed by multiple fields.
Conclusion
Implementing AutoSerial generation for compound keys significantly enhances data consistency, reduces manual errors, and ensures strict uniqueness in key-sensitive modules. This configuration is highly recommended for all developers and module creators working with Merciglobal Cloud ERP.
For more technical details and extended documentation, visit: Merciglobal Cloud ERP Documentation