Validation and triggers in MVC models
Separates data validation from trigger-based filling.
Overview
A trigger derives a value but does not replace model validation. FWStruTrigger returns four elements: source field, target field, condition and execution for AddTrigger. This example uses fictional fields and no table lookup; both fields must exist. VldData checks model/submodels; CommitData requires successful validation and correctly configured persistence. Avoid duplicate side effects across UI and save events. (Sources: refs. 1–3.)
Commented example
// Fragment: oStruct contains character fields ED_ORIG and ED_DEST.
Local aTrigger := FWStruTrigger("ED_ORIG","ED_DEST","Upper(M->ED_ORIG)",.F.,"",0,"","","ED704")
// Fixed author-defined rule, not an external expression.
oStruct:AddTrigger(aTrigger[1],aTrigger[2],aTrigger[3],aTrigger[4])Registers the trigger definition without activating a model or writing data. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Test source/target, cycles and rejected validation. Textual rules are code, not free user input.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.