Monday, October 4, 2021

Create Multiple number sequence for one EDT In D365FO using X++

I got a requirement in order to create Multiple number sequence based on type for newly created purchase order in D365FO.

The similar requirement is already exists in fixed assets. Same way I followed here.


1. I created new table with 3 fields.

  •         Purch type.
  •         Description.
  •         Number sequence code.(Organization module --> Number sequences(form) --> Number sequence code(field)).
                                                




Organization module --> Number sequences(form) 
    Create new number sequence as per you requirement.


2.  Added "Purch type" field in purchase order and added relation to purch table and my table.


3. written code in below classes.

Form data source field(PurchaseType) modified method:

    [ExtensionOf(formDataFieldStr(PurchCreateOrder, PurchTable, PurchaseType))] final class PurchCreateOrderFormControl_Extension { public void modified() { FormDataObject formDataObject = any2Object(this) as FormDataObject; PurchTable purchTable = formDataObject.datasource().cursor(); NumberSeq purchaseOrderNumberSeq = element.purchaseOrderNumberSeq as NumberSeq; ; next modified(); if(purchaseOrderNumberSeq) { purchaseOrderNumberSeq.abort(); } purchaseOrderNumberSeq = purchTable.initPONumberSeq(); element.purchaseOrderNumberSeq = purchaseOrderNumberSeq; purchTable.PurchId = purchaseOrderNumberSeq ? purchaseOrderNumberSeq.num() : nullValueFromType(Types::String); purchId = purchTable.PurchId; FormDataUtil::getFormDataSource(purchTable).refresh(); } }


Purch table method:

    [ExtensionOf(tableStr(PurchTable))] final class PurchTable_Extension { public NumberSeq initPONumberSeq(PurchaseType _purchaseType = " ") { NumberSeq purchaseOrderNumberSeq = PurchaseTypeTable::getNumberSeqForType( _purchaseType ? _purchaseType : this.PurchaseType); return purchaseOrderNumberSeq; } }

PurchaseTypeTable(My table) method: 

    public class PurchaseTypeTable extends common { public static NumberSeq getNumberSeqForType(PurchaseType _purchaseType) { PurchaseTypeTable purchaseTypeTable = PurchaseTypeTable::find(_purchaseType); NumberSeq purchaseOrderSeq; PurchTable purchTable; if (purchaseTypeTable.AutoNumberSequenceTable) { purchaseOrderSeq = NumberSeq::newGetNumFromId(purchaseTypeTable.AutoNumberSequenceTable, true); } return purchaseOrderSeq; } }

Form close method:

    [ExtensionOf(formStr(PurchCreateOrder))] final class PurchCreateOrderForm_Extension { public numberseq purchaseordernumberseq; public PurchId purchId; public void close() { if (!purchtable.recid && purchaseordernumberseq) { purchaseordernumberseq.abort(); } } }

Form data source write method:

    public void write() { if (purchaseordernumberseq) { purchaseordernumberseq.onNumberUsed(purchTable.PurchId, purchId); } }

Keep daxing!!

No comments:

Post a Comment