OnValidate() & OnLookup()

sridharsridhar Member Posts: 171
What is the difference between OnValidate() & OnLookup() ? Any Example please...

Comments

  • garakgarak Member Posts: 3,263
    Use the help.

    OnValidate (Fields)
    The C/AL code in this trigger is executed when the system validates user input.

    Applies to
    Fields

    Comments
    The system executes this trigger after it executes its default validation behavior.

    If there is an error in the C/AL code you enter into this trigger, the system displays an error message, leaves the user's entry in the field, but does not write the record to the database.

    OnLookup (Fields)
    The C/AL code in this trigger causes the system to display a lookup window you design.

    There are three layers of lookups in the system. The first layer is the system's default lookup behavior, which provides a lookup into the table with no filters applied or any other special parameters. You can use this trigger to define a lookup for the field, which the system will use in place of its standard behavior. Finally, for the text box, you can define a lookup the system will use in place of the system's standard behavior or the lookup defined in this trigger - see OnLookup for a description of that trigger.

    Applies to
    Fields

    Comments
    The system executes this trigger instead of its default lookup behavior.

    When using this trigger you typically first take a value from the field to determine what filters to apply or any other special parameters. Then you run the lookup form in modal mode. Next you transfer the value the user selects back to the field when the user chooses OK.

    If there is an error in the C/AL code you enter into this trigger, the system closes the lookup form.

    Examples for Onvalidate and onlookup. The lookup trigger is using, when you will for example run a form in Lookupmode.
    Code - OnValidate()
    //after person makes an input he will show a message
    message('%1 / %2 / %3',TABLECAPTION,FIELDCAPTION(Code),'Code - OnValidate()');
    
    Code - OnLookup()
    //if this trigger has lines, the control on a form which ref. 
    //to this field becomes an Arrow
    message('%1 / %2 / %3',TABLECAPTION,FIELDCAPTION(Code),'Code - OnLookup()');
    if form.runmodal(Form::XYZ,VarRec) = Action::Lookupok then
      validate(Code,VarRec.code);
    

    Regards
    Do you make it right, it works too!
  • sridharsridhar Member Posts: 171
    Thanks Garak
Sign In or Register to comment.