Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Validation and triggers in MVC models

Separates data validation from trigger-based filling.

Validation and triggers in MVC modelsAdvPL
01 · OVERVIEW

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.)

03 · PRACTICAL EXAMPLE

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])
Expected result

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.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. FWStruTrigger. Array de definição e AddTrigger. Accessed on 2026-10-28.
  2. TOTVS. FWFormModel. VldData e CommitData. Accessed on 2026-10-28.
  3. Atilio. dan-atilio/AdvPL. Exemplos/Vídeo Aulas/018 - Modelo 1 em MVC/zModel1.prw. Arquivo completo analisado; adaptação editorial. Accessed on 2026-10-28.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha