Compiere has the ability to dynamically create default field values when a new record is created (SQL, constant, preferences). In addition to this, Automatic Assignments allow to set values after the user pressed save, just before a record is saved. This could be used to create a default value without user intervention or if the user fails to define a value. Another use is to assign a certain value based on other fields.
Automatic Assignments are basically declerative before-insert/update/delete trigger and the main use is to complete records based on user entered values, set status, routing. It is an easy alternative to extending the business class and modifying the beforeSave method.
Examples include: In a Lead assign the sales rep based on the country/region of the lead;
The Automatic Assignment allows you to add business logic without programming nor impact on migration to new versions and with that an ideal Customization tool. It acts like a Trigger and it's execution is logged.
You define the auto assignment for a certain table and select the situation the assignment should take place: e.g., when a record is Created and/or Updated. You can add the restriction that the record cannot modified if processed (for documents are assumed to be read/only after processing).
For each table, you can define any number of Target columns to be modified. The new value can be a constant or be calculated via SQL. The new value can be always assigned or only if the current value is (not) NULL. If you define a sql statement to result in the new value and it fails, the assignment is not performed.
You can add additional Criteria to limit the execution of the assignment. You can compare any column in the record with constants or SQL results. If you use a sql statement and it fails, it is treated as returning a NULL value (and with that the criteria usually fails). Multiple criteria could be linked via AND or OR logic.
In summary, the assign target results in the SET clause and the criteria in the WHERE clause of the virtiual update statement.
The sql statements used for the value assignment or criteria must be SELECT statements in which you could variables. If the criteria is met and the assignment was performed, a log record with the old and new value is created.
The timing sequence perspective of values:
- New Record created
- Default Values and Preferences
- User enters/updates values
- Record saved
- Auto Value Assignment
- PO.beforeSave(..) method
- Database commit
- PO.afterSave(..) method
Assign Sets are available in Compiere since release 3.0