Wednesday, April 24, 2024

How to create a filter on display method using view Dynamics 365 Finance and Operations

Form fields that are based on display methods are not filterable, but in some cases, the client wants those fields filterable. There are two ways to make display fields filterable we will explain on this blog only the best way to do it (use best practice).

In our case Invoice Date field field into project expense journal form, invoice date is comes from projinvoicejour which is not part of our form. for this created view with ProjCostTrans and created method like below to get invoice date.


public class ProjCostTrans extends common
{
    private static str expensetransInvoicedate()
    {
        str expressionExp = strFmt(
            @"SELECT TOP 1 PROJINVOICEJOURlocexp.INVOICEDATE
                FROM %1 AS ProjProposalCostLoc
                JOIN %2 AS PROJINVOICEJOURlocexp
                ON PROJINVOICEJOURlocexp.ProposalId = ProjProposalCostLoc.ProposalId
                WHERE ProjProposalCostLoc.TransId = %3",
            (new SysDictTable(tableNum(ProjProposalCost))).name(DbBackend::Sql),
            (new SysDictTable(tableNum(PROJINVOICEJOUR))).name(DbBackend::Sql),
            SysComputedColumn::returnField(tableStr(ProjCostTrans), identifierStr(ProjCostTrans),
            fieldStr(ProjCostTrans, TransId)));
        return expressionExp;
    }
}

once method is completed, add view as data source in expense journal form and drag invoice date filed into grid.

How to calculate due date in x++?

////      for aging report

class Duedate_CustAging
{
    public static void main(Args _args)
    {
        CustTrans               CustTrans;
        CustInvoiceJour         custInvoiceJour;
        ttsBegin;
        while select forupdate custInvoiceJour where CustInvoiceJour.Payment =='Test'
                        && CustInvoiceJour.DueDate == CustInvoiceJour.InvoiceDate
                          //  && CustTrans.Invoice=='INV-0000001623'
        {
            CustInvoiceJour.DueDate = PaymTerm::find(CustInvoiceJour.Payment).due(CustInvoiceJour.InvoiceDate);
            CustInvoiceJour.update();
        }
        ttsCommit;
    }
}

////      for Cust Trans
class DuedateCusttrans_OpenClass
{
    public static void main(Args _args)
    {
        CustTransOpen       CustTransOpen;
        CustTrans           CustTrans;
        
        ttsBegin;
        while select forupdate CustTransOpen join CustTrans where CustTrans.RecId == CustTransOpen.RefRecId 
                    && CustTrans.AccountNum == CustTransOpen.AccountNum 
                    && CustTrans.PAYMTERMID ==CustParameters::find().CustPaymTermId
                    && CustTransOpen.DueDate == CustTransOpen.TransDate  && CustTrans.Invoice !=''
                    //  && CustTrans.Invoice=='INV-0000001623'
        {
            CustTransOpen.DueDate = PaymTerm::find(CustTrans.PAYMTERMID).due(CustTransOpen.TransDate);
            CustTransOpen.update();
        }
        
        ttsCommit;
        
        info('Due date has been Updated');
    }

}