Getting and setting MVC model values
oModel:GetValue(cIdForm,cIdField); oModel:SetValue(cIdForm,cIdField,xValue)Reads fields and assigns values through Model validation.
Overview
On the root model, GetValue takes submodel ID and field; SetValue also takes the new value and returns logical. The configured model operation affects validation. The grid object has a different signature acting on its current row. LoadValue is not a generic replacement: it requires SetValue in the call stack and skips field validation. Successful SetValue does not confirm persistence; VldData and CommitData are later controlled steps. (Sources: refs. 1–2.)
Syntax
oModel:GetValue(cIdForm,cIdField); oModel:SetValue(cIdForm,cIdField,xValue)Commented example
#Include "Protheus.ch"
User Function Ed560()
// Model, IDs and operation must be prepared; blocks not invoked.
Local bRead := {|oModel,cForm,cField| oModel:GetValue(cForm,cField)}
Local bUpdate := {|oModel,cForm,cField,xValue| oModel:SetValue(cForm,cField,xValue)}
ConOut(ValType(bRead)+ValType(bUpdate))
Return NilPrints BB. When integrating, check SetValue’s logical result and model errors. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Use actual structure fields/IDs, inspect errors and avoid bypassing validation with direct writes. In grids, preserve position and validate row/model before persistence.
- 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.