Wednesday, 21 June 2023

Join view as a Second / Secondary data source in D365 F&O or AX 2012

 In this post I am going to discuss about how to add View as a Secondary data source in form and use it in the grid.


1. Create a form with table as a Root data source.



2. Create a Grid with this data source.



3. Form view, notice that right now  the invoice number field is a Display method and we are going to get it by using view



4. Create a AOT query and View for that query


add simple query to a view

View 

5. Add View as a Secondary data source


6. Join the view with required data source in this I am joining with VendPackingSlipTransInvoice Data source, you can join with any data source you want

7. Go to the VendPackingSlipTransInvoice data source and override the init method of the datsource

8. Add a link between the fields you want to provide the link.

9. Use datasource 






Tuesday, 20 June 2023

How to change the purchase order state to Draft?

 The following post is used to show, how to change the Purchase order to the "Draft" state. Sometimes to update simple fields it might check for the versioning state of the purchase order and it will through the following error "Changes to the document are only allowed in state Draft because change management is activated". For this case, you can use the following code.


/// <summary>

    /// Change the purchase order state to draft

    /// </summary>

    /// <param name = "_purchTable">Purchase order buffer</param>

    protected void changeState(PurchTable _purchTable)

    {

        if (_purchTable.ChangeRequestRequired && _purchTable.DocumentState >= VersioningDocumentState::Approved)

        {

            VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();

        }

    }