Tuesday 10 September 2019

Use Coc(Chain of command) for methods on form datasource/Controls/DataSource fields D365 Finance and Operations

Hi folks, we all might have faced the situation where you needed to use the methods on datasources/controls of d365 standard forms.
Its much easier than you think, only drawback is you don't really have a power of intellisense on this.
But, who cares as long as it works.

Scenario:
Form: SalesTable
Datasource: SalesTableExt (Custom table)
Task: to fillup value in field salestable (recId of salesTable data) on datasource write method.

///
/// extension class for SalesTableExt on form SalesTable
///
[ExtensionOf(formdataSourceStr(SalesTable, SalesTableExt))]
final class SalesTablefdsSalesTableExtTest_Extension
{
    ///    
    /// write method on datasource
    ///    
    void  write()
    {
        this.writePre();
        next write();
    }

    ///    
    /// prewrite method
    ///    
    protected void writePre()
    {
        this.resolveSalesId();
    }

    ///    
    /// salesId(recid) update in SalesTableExt
    ///    
    protected void resolveSalesId()
    {
        FormDataSource      ds              = this;
        SalesTable          salesTable      = ds.formRun().dataSource(formdataSourceStr(SalesTable, SalesTable)).cursor();
        SalesTableExt       salesTableExt   = ds.cursor();

        salesTableExt.SalesTable = salesTable.RecId;
    }

}

Attribute
[ExtensionOf(formdataSourceStr(SalesTable, SalesTableExt))]
defines the object where COC has to be performed.

In a similar way, we can use Coc on form controls. Only difference would be there on attribute for class, it would be like
[ExtensionOf(formControlStr(SalesTable, SalesTableExt_SalesTable))]


and if needed on form datasource control, then attribute would be like
[ExtensionOf(formDatasourceControlStr(SalesTable, SalesTableExt, SalesTable))]


Mind, this can be done only post Update 22.

Thanks!!! See you on next post......