Working with numbersequences – On forms

  • February 18, 2010
  • 0 Comments

When you want to implement NumberSequences in a Ax form (new numbersequence when you create a record etc.) you can just implement the ‘numberSeqFormHandler’.

Step-by-step:

  • Define a object of the type ‘NumberSeqFormHandler‘ in the ClassDeclaration of the form
    1
    2
    3
    4
    
    public class FormRun extends ObjectRun
    {
        NumberSeqFormHandler            numberSeqFormHandler;
    }
  • Create a new method on your form that create a new instance of the ‘numberSeqFormHandler’ object or creates a new object when it isn’t instanciated.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    NumberSeqFormHandler numberSeqFormHandler()
    {
        ;
        if (!numberSeqFormHandler)
            numberSeqFormHandler = NumberSeqFormHandler::newForm(TestParameters::numRefTEST().NumberSequence,
                                                                 element,
                                                                 TestTable_DS,
                                                                 fieldnum(TestTable,TEST)
                                                                );
        return numberSeqFormHandler;
    }
  • Complete some of the existing methods with the correct method of the ‘numberSeqFormHandler‘ object:
    • Table : Create() –> The user creates a new record in the data source.
      1
      2
      3
      4
      5
      6
      7
      
      public void create(boolean _append = false)
      {
          ;
          element.numberSeqFormHandler().formMethodDataSourceCreatePre();
          super(_append);
          element.numberSeqFormHandler().formMethodDataSourceCreate();
      }
    • Table : Delete() –> The user deletes a record in the data source.
      1
      2
      3
      4
      5
      6
      
      public void delete()
      {
          ;
          element.numberSeqFormHandler().formMethodDataSourceDelete();
          super();
      }
    • Table : Write() –> The user inserts a new record or updates an existing one.
      1
      2
      3
      4
      5
      6
      7
      8
      
      public void write()
      {
          ;
          ttsbegin;
          super();
          element.numberSeqFormHandler().formMethodDataSourceWrite();
          ttscommit;
      }
    • Table : validatWrite() –> new or updated record is to be written.
      1
      2
      3
      4
      5
      6
      7
      8
      
      public boolean validateWrite()
      {
          boolean ret;
          ;
          ret = super();
          ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
          return ret;
      }
    • Table : linkActive() à The user selects a new record in a form that has a data source linked to another data source.
      1
      2
      3
      4
      5
      6
      
      public void linkActive()
      {
          ;
          element.numberSeqFormHandler().formMethodDataSourceLinkActive();
          super();
      }
    • Close() –> The form is closed.
      1
      2
      3
      4
      5
      6
      7
      
      public void close()
      {
          ;
          if (numberSeqFormHandler)
              numberSeqFormHandler.formMethodClose();
          super();
      }