16 Eylül 2021 Perşembe

Dynamics 365 F&O - Extensions overview

 I worked a few AX upgrade projects. Unfortunately multi-layer architect is so painful with upgrade projects. Seem this problem is solved with extensions approach.

When you wanted to add fields/indexes/relations... in tables/data entities or controls in forms you create extensions directly:



Enums doesn't use numbers (at least in development environment) anymore. This's very good for upgrade projects. Unfortunately I lived problems about added elements without any gap to system enums. How it was a problem:

Sample, a system enum goes 1-2-3-4-5 and a developer added a new element. He/she actually should add new element as at least from 20 maybe 30 but added from 6. And in new version Microsoft added 6. :)

In the case of writing code there are some shortcuts. You can open related object and click right  mouse for copy template:

A sample class method extension:

 [PostHandlerFor(classStr(LedgerJournalCheckPost), methodStr(LedgerJournalCheckPost, run))]
    public static void LedgerJournalCheckPost_Post_run(XppPrePostArgs args)
        LedgerJournalCheckPost      post = args.getThis() as                         LedgerJournalCheckPost;

        LedgerJournalTable          journalTable;

        journalTable = post.parmLedgerJournalTable();



You can put this method in any class and this method will run after run method. If we selected Pre-event, it would be run before run.

In this case we extend ondeleted of a table:


 [DataEventHandler(tableStr(LedgerJournalTable), DataEventType::Deleted)]
    public static void LedgerJournalTable_onDeleted(Common sender,             DataEventArgs e)

    LedgerJournalTable       ledgerJournalTable = sender as                     LedgerJournalTable;


If we want to add a new method of a table, things change a bit. We need a new class named  Table name and  _Extension word like this:

final class AGC_ABCRCreditTable_Extension
    public void updateDefaultDimension()
            this.DefaultDimension = 11111;



Access to modifiedfield event of a table:

[DataEventHandler(tableStr(ABCRCreditTable), DataEventType::ModifiedField)]
    public static void ABCRCreditTable_onModifiedField(Common sender, DataEventArgs e)
        ABCRCreditTable         creditTable = sender as                             ABCRCreditTable;
        ModifyFieldEventArgs    eventArgs = e;
        int                     id = eventArgs.parmFieldId();
            case fieldNum(ABCRCreditTable,CreditAccount):
                if (ABCRParameters::find().CRCreditAccountType ==                         ABCRAccountType::Vend)
            case fieldNum(ABCRCreditTable,StrategyNumber):



Override form lookup method:

  [FormDataSourceEventHandler(formDataSourceStr(ABCRCreditTable, ABCRCreditTable), FormDataSourceEventType::Initialized)]
    public static void ABCRCreditTable_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
        var overrides = new AGC_CreditTableExt();
        sender.object(fieldNum(ABCRCreditTable,                 TradeNumber)).registerOverrideMethod(methodStr(FormDataObject, lookup),
            methodStr(AGC_CreditTableExt, lookupTrade), overrides);

With this sample we make run code at up in forms data source OnInitialized event. We override datasource tradenumber fields lookUp method with  AGC_CreditTableExt class lookupTrade method.  You can write this code in any class. I choosed AGC_CreditTableExt .

Recently I learned another extension method for override lookups by Peter Ramer's blog by CancelSuperCall() .


20 Ağustos 2021 Cuma

Dynamics 365 F&O - Extend decimal point beyond five

 Dynamics 365 F&O supports six decimal points. So just extend decimal point field  of extended data type doesn't enough:



We need to do a few tricks more:

In first we create a new field for save decimal point and be sure this method below to run after every write (We can call from update/insert methods).

  public void updateInterestRateDecimals()
        this.InterestRateDecimal = (this.InterestRate - real2int(this.InterestRate) ) *


Than we modify postLoad like this:

public void postLoad()
        if (this.InterestRateDecimal != 0)
            this.InterestRate = real2int(this.InterestRate) +
                this.InterestRateDecimal / 100000000;