Usina BRAdvPL Guide
Sign in
← All topics
MVC ENTRY POINTUnder review

ITEM

User Function ITEM()

MATA010 maintains product records in SB1. Its documented MVC model identifier is ITEM: implement User Function ITEM() and dispatch the events received in PARAMIXB[2]. Conventional names remain in the mapping for reference and compatibility.

MATA010MVCITEMPARAMIXBMODELPOSMODELCOMMITTTS
01 · OVERVIEW

Overview

Each card is an event received by the same User Function ITEM(), not a separate function. All code panels repeat the same complete dispatcher: use one ITEM source and combine handling there. The diagram shows phases; an event is not guaranteed to run only once.

02 · SYNTAX

Syntax

User Function ITEM()

Parameters

PARAMIXB[1]
OExecution context

Model or form object, depending on the event.

PARAMIXB[2]
CExecution context

MVC event identifier received by function ITEM.

PARAMIXB[3]
CExecution context

Form or submodel identifier; do not confuse it with the entry function name.

Return value

MODELPOS validates the whole model and expects logical. MODELCOMMITTTS runs inside the transaction; MODELCOMMITNTTS runs outside it. Returning Nil from a persistence event does not block processing. Standard code controls Begin Transaction and completion.

03 · PRACTICAL EXAMPLE

Skeleton example · ITEM

#Include "Protheus.ch"
#Include "FWMVCDef.ch"

/*/{Protheus.doc} ITEM
    One function receives the events for model ITEM.
    @type User Function
    @author Usina.BR
    @since 31/10/2026
    @return variant
/*/
User Function ITEM()
    Local aContext := PARAMIXB
    Local oContext := Nil
    Local cEvent := ""
    Local cForm := ""
    Local xReturn := .T.

    // Check the envelope before reading documented positions.
    If ValType(aContext) != "A"
        Return xReturn
    EndIf
    If Len(aContext) < 3
        Return xReturn
    EndIf
    If ValType(aContext[2]) != "C"
        Return xReturn
    EndIf
    oContext := aContext[1]
    cEvent := aContext[2]
    cForm := aContext[3]

    Do Case
    Case cEvent == "MODELVLDACTIVE" .Or. ;
         cEvent == "MODELPOS" .Or. cEvent == "FORMPOS"
        // No custom rule: allow validation in this skeleton.
        xReturn := .T.
    Case cEvent == "BUTTONBAR"
        // No extra buttons in this example.
        xReturn := {}
    Case cEvent == "FORMCOMMITTTSPRE" .Or. ;
         cEvent == "FORMCOMMITTTSPOS"
        // Before form persistence; the return does not block processing.
        xReturn := Nil
    Case cEvent == "MODELCOMMITTTS"
        // Complementary handling inside the transaction, with no external effect.
        xReturn := Nil
    Case cEvent == "MODELCOMMITNTTS"
        // Handling outside the transaction; do not run the same integration twice.
        xReturn := Nil
    EndCase
Return xReturn
Expected result

Editorial skeleton, not compiled or executed in Protheus during this review. It neutrally dispatches the displayed events, implements no business rules, writes no tables and calls no external services. Validate release-specific events, submodels and operations before customizing. Do not publish multiple sources containing User Function ITEM().

BEST PRACTICES
  • The MVC hook is named ITEM, not MATA010 or A010GRV. PARAMIXB[1] carries the object/context, [2] the event and [3] the form/submodel. Check event-specific extra parameters before accessing them.
COMMON PITFALLS
  • The mapping relates intent, not identical signatures or returns. Conventional MTA010OK returns logical; FORMCOMMITTTSPRE expects no return. To block total model validation, use the logical MODELPOS return according to its contract. MT010BRW is listed as unchanged, which does not prove that every legacy hook runs in every release.

Related content

REFERENCES
  1. TOTVS. Ponto de entrada MVC para as rotinas MATA010, MATA020 e MATA030. Central de Atendimento. 29 dez. 2021. Consulta: 31 out. 2026.
  2. TOTVS. Manual AdvPL utilizando MVC. Versão 4.0, maio 2015, p. 95–100. Tabela de eventos e retornos; trechos indexados consultados em 31 out. 2026.
  3. TOTVS. Ponto de Entrada Padrão do MVC. Conferir o contrato da versão instalada.
Status
Under review
Page created on
Last reviewed on
Original language
Português
Reviewed by
Usina.BR

Was this content helpful?

👍 Like 0👎 Dislike 0

Sign in to rate this article.

0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha