Friday, November 5, 2021

How to get datasource on a listPage (ListPageInteraction class) in D365fo

 Hi guys, Today we see how to get datasource on a listPage (ListPageInteraction class) in D365fo. I got a requirement like I have to select multiple records. If the selected record type is different I have to disabled few buttons.


First I took the extension for the standard class and wrote the code in selectionChanged method.

    

[ExtensionOf(classStr(PurchReqCreatePurchListInteraction))]

public final class Test_PurchReqCreatePurchListInteraction_Extension
{
    public void selectionChanged()
    {
        next selectionChanged();

        ListPage        listPage = this.listPage();
        boolean         check = false;
        PurchReqLine    purchReqLine,activeRecord = listPage.activeRecord(tableStr(PurchReqLine));
        FormDataSource  purchReqLine_DS = FormDataUtil::getFormDataSource(purchReqLine);
        //   FormDataSource  purchReqLine_DS = listPage.activeRecord(queryDataSourceStr(PurchReqCreatePurch, 
                            //PurchReqLine)).datasouce(); 
                            //listPage.activeRecord(queryDataSourceStr(ReqTransPOListPage,ReqPO)).dataSource();
        // int selectedRows = purchReqLine_DS .recordsMarked().lastIndex();
        PurchReqTable   purchReqTable;
        ;

        if (activeRecord)
        {
            for (purchReqLine = getFirstSelection(purchReqLine_DS); purchReqLine; purchReqLine = purchReqLine_DS.getNext())
            {
                if (!purchReqTable)
                {
                    purchReqTable = purchReqLine.purchReqTable();
                }

                check = purchReqTable.Test_Type != purchReqLine.purchReqTable().Test_Type ? false : true;

                this.listPage().actionPaneControlEnabled(formControlStr(PurchReqCreatePurchListPage,
                                                PurchaseOrderMenuItemButton), check);
                this.listPage().actionPaneControlEnabled(formControlStr(PurchReqCreatePurchListPage,
                                                PurchAgreementGenerator), check);
                if (!check)
                {
                    break;
                }
            }
        }
    }
}


Keep Daxing!!

No comments:

Post a Comment