Tuesday, February 22, 2022

How to Setup number sequence in standard or custom form In D365FO using x++

 How to Setup number sequence in form In D365FO X++.

Create number sequence for new field : Link 

  • After creation of new number sequence we need to setup in one form. I got a requirement to setup new number sequence in standard from.
  • For this I have used the extensions(COC). Please check.
  • If you need for custom form just copy the below methods and pasted in you'r form.
  • The below code is for both custom and standard forms.  

On Form data source.

   [ExtensionOf(formDataSourceStr(MyForm, MyTable))]

final class MyFormDataSource_Extension { void write() { next write();//COC //super(_append); element.numberSeqFormHandler().formMethodDataSourceWrite(); } void delete() { element.numberSeqFormHandler().formMethodDataSourceDelete(); next delete();//COC //super(_append); } void create(boolean _append) // If created externally { element.numberSeqFormHandler().formMethodDataSourceCreatePre(); next create(_append);//COC //super(_append); element.numberSeqFormHandler().formMethodDataSourceCreate(); // this.object(fieldNum(MyTable, Field1)).modified(); // If any modified method is written in data source field level // By the above line we can call, } // In standard they are added below 2 methods. public void linkActive() { element.numberSeqFormHandler().formMethodDataSourceLinkActive(); next linkActive();//COC //super(); } public boolean validateWrite() { boolean ret; MyTable myTable;//COC myTable = this.cursor();//COC if (!myTable.Field1) { element.numberSeqFormHandler().formMethodDataSourceCreate(true); } ret = next validateWrite();//COC //ret = super(); ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(true) && ret; return ret; } } On Form.
[ExtensionOf(formStr(MyForm))] final class MyFormDataSource_Extension { public NumberSeqFormHandler numberSeqFormHandler;// global variable public NumberSeqFormHandler numberSeqFormHandler() { if(!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm( myParameters::numRefMyID().NumberSequenceId, this, this.MyTable_ds, fieldNum(MyTable, Field1)); } return numberSeqFormHandler; } void close() { if (numberSeqFormHandler) { numberSeqFormHandler.formMethodClose(); } next Close();//COC //super(); } }

Reference: 

Keep Daxing!!

No comments:

Post a Comment