Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Automatic routines using MVC models

Uses model rules with explicit validation and persistence.

Automatic routines using MVC modelsAdvPL
01 · OVERVIEW

Overview

Prepare an environment only if the caller does not provide one. Load the model, set operation, activate, assign values by valid IDs and run VldData before CommitData. Check relevant returns, retrieve GetErrorMessage on failure and finish deactivation/destruction according to object contract. Errors may contain field values, so minimize logging. This exercise builds a validator block without writing; CommitData is commented to identify the unexecuted persistence stage. (Sources: refs. 1–2.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed634()
    // Requires an active populated model; block not invoked.
    Local bValidate := {|oModel| oModel:VldData()}
    // After validation, only in the authorized flow: oModel:CommitData()
    ConOut(ValType(bValidate))
Return Nil
Expected result

Creates B without validating or writing a real object. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • VldData is not commit. LoadValue is not a general substitute for SetValue to skip validation.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FWFormModel. Seções SetRelation, SetPrimaryKey, SetOperation, VldData, CommitData e GetErrorMessage. Accessed on 2026-10-27.
  2. TOTVS. FWLoadModel. Accessed on 2026-10-27.
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