Wednesday, March 13, 2019

NAV - How to set a field (and option field) to be mandatory or required


  • On the field properties, set NotBlank = Yes
  • On Page trigger, error the onvalidate if less than ! for text or 0 for numbers
  • On the Page, add your logic to the OnQueryClosePage
  • PAGE.RUN can be used to open a page and set focus on a field
 field(Comment; Comment)
                {
                    ShowMandatory = true;
                    trigger OnValidate()
                    begin
                        If Comment < '!' then
                            error('Comment cannot be blank');
                    end;
                }

OnQueryClosePage(CloseAction : Action None) : Boolean
    IF "Address 2" = '' THEN BEGIN
        MESSAGE('Please enter Address');
        EXIT(FALSE);
          END;

          In AL, create a default option value, set the default value on new, then check for that specific value

          pageextension 50040 "Sales Order - Layout" extends "Sales Order"
          {    
          trigger OnNewRecord(BelowxRec: Boolean)
              begin
                  "Pickup Option" := "Pickup Option"::" ";

              end;    
          trigger OnQueryClosePage(Closeaction: Action)Boolean
              begin
                  IF "Pickup Options" = "Pickup Options"::" " THEN
                      Message('Please select a Pickup Option');
                  EXIT(false);
              end;
          }

          ENUMS
          enum 50000 PickupOption
          {
              Extensible = true;
              value(0; " "{ }
              value(1; Delivery{ }
              value(2; Pickup{ }
          }

          No comments:

          Post a Comment