Usina BRAdvPL Guide
Sign in
← All topics
ENTRY POINTPublished

MT120OK

MT120OK() --> lRetorno

Runs user-specific validations on purchase order items before the process continues.

Entry pointsPurchasingPurchase orderMATA120MATA121GetDadosValidation
01 · OVERVIEW

Overview

MT120OK is an entry point for the Purchase Order / Delivery Authorization routine. It is triggered at the end of A120TudOk(), after confirming the GetDados items and before the purchase order dialog footer. Its return controls whether the process continues: .T. allows it to proceed and .F. interrupts validation.

02 · SYNTAX

Syntax

MT120OK() --> lRetorno

Return value

lRetorno, logical. Return .T. to allow the validated items to continue the process. Return .F. to interrupt the process when a user-specific validation rule is not met.

03 · PRACTICAL EXAMPLE

Product, quantity and price validation

#Include "TOTVS.ch"

User Function MT120OK()
    Local nProductPos := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_PRODUTO"})
    Local nQtyPos     := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_QUANT"})
    Local nPricePos   := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_PRECO"})
    Local lValid      := .T.
    Local nLine       := 0

    For nLine := 1 To Len(aCols)
        If !aCols[nLine][Len(aCols[nLine])] .And. !Empty(aCols[nLine][nProductPos])
            If Empty(aCols[nLine][nQtyPos]) .Or. Empty(aCols[nLine][nPricePos])
                MsgAlert("Enter quantity and price for product " + aCols[nLine][nProductPos], "Order validation")
                lValid := .F.
                Exit
            EndIf
        EndIf
    Next nLine

Return lValid
Expected result

The example locates fields in aHeader, loops through aCols lines and prevents continuation when an entered product has no quantity or price.

04 · PRACTICAL EXAMPLE

Minimum structure

#Include "TOTVS.ch"

User Function MT120OK()
    Local lReturn := .T.

    // Run additional purchase item validations here.
    // Return .F. to interrupt the process.

Return lReturn
Expected result

Minimum structure for creating an additional validation controlled by the logical return of the entry point.

BEST PRACTICES
  • Use AScan() over aHeader to locate field positions before validation.
  • Initialize the return value as .T. and change it to .F. only when a rule fails.
  • Use Exit to stop the loop as soon as the first relevant inconsistency is found.
  • Show a clear message when validation prevents the process from continuing.
  • Test orders with one line, multiple lines, blank lines and lines marked for deletion.
COMMON PITFALLS
  • Do not assume C7_PRODUTO, C7_QUANT and C7_PRECO positions are fixed; locate fields in aHeader before accessing aCols.
  • Pay attention to the last position of the aCols line, often used to indicate a marked/deleted browse line.
  • Avoid returning .F. without explaining to the user why the process was interrupted.
  • Do not run slow processing in this validation without assessing the impact on order confirmation.
  • Avoid legacy includes in new code when they are not required; keep only the dependencies needed by the source.

Related content

REFERENCES
  1. TOTVS. MT120OK - User-Specific Validations. TDN. Created by Raphaela Marcela Ferreira, last modified by Philipe dos Santos Pompeu on Jul. 7, 2023. Accessed on Aug. 28, 2026.
  2. COSTA, Adilio. Entry Point MT120OK - User-Specific Validations. ProtheusAdvpl, Oct. 22, 2025. Accessed on Aug. 28, 2026.
  3. Entry Points — AP 7 7.10. Historical base used by AdvPL Guide for cross-reference with purchase order routines.
Status
Published
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