How to create and run the Runbase class in D365

In this article, you will learn how to create and run a class that extends RunBase in D365. 


Step by step, please see the below code:

Create a class and extend runbase. In this case, i create the class with name as "SumCustomerTransaction".


For example: 


Here is the code for extending the runbase class:




You can copy the code here:

public class SumCustomerTransaction extends RunBase 

    DialogField     dialogAccount; 

    DialogField     dialogFromDate; 

    DialogField     dialogToDate; 

    CustAccount    custAccount; 

    FromDate         fromDate; 

    ToDate              toDate; 

    #DEFINE.CurrentVersion(1) 

    #LOCALMACRO.CurrentList 

        custAccount, 

        fromDate, 

        toDate 

    #ENDMACRO 

    public Object dialog() 

    

        DialogRunBase     dialog; 

        DialogGroup         groupPeriod; 

        dialog = super(); 

        dialogAccount  = dialog.addFieldValue(extendedTypeStr(CustAccount), custAccount); 

        groupPeriod     = dialog.addGroup("Period"); 

        dialogFromDate  = dialog.addFieldValue(extendedTypeStr(FromDate), 

                                                                            fromDate, "Period from"); 

        dialogToDate       = dialog.addFieldValue(extendedTypeStr(ToDate), toDate, "Period to"); 

       

        return dialog; 

    

    public boolean getFromDialog() 

    {

        boolean ret; ret = super(); 

        custAccount = dialogAccount.value(); 

        fromDate = dialogFromDate.value(); 

        toDate = dialogToDate.value(); 

        return ret; 

    

    public container pack() 

    

        return [#CurrentVersion,#CurrentList]; 

    }

    public boolean unpack(container _packedClass)

    

        Version version = RunBase::getVersion(_packedClass); 

        switch (version) 

        

            case(#CurrentVersion) : 

                [version,#CurrentList] = _packedClass; 

            break; 

            default : 

                return false; 

        

        return true; 

    

    static client server ClassDescription description() 

    

        return "Sum customer transactions";     

    }

    public void run() 

    

        CustTrans custTrans; 

        select sum(AmountMST) 

            from custTrans 

                where custTrans.AccountNum == custAccount 

                && custTrans.TransDate >= fromDate 

                && custTrans.TransDate <= toDate; 

        info(strFmt("Sum equals %1", custTrans.AmountMST));

   

    static void main(Args _args) 

    

        SumCustomerTransaction demoRunBase; 

        demoRunBase = new SumCustomerTransaction(); 

        if (demoRunBase.prompt()) 

        

            demoRunBase.run(); 

        

    }

}




Comments

Popular posts from this blog

How to customize electronic reporting in D365

Batch parallelism or multithreading in Dynamics 365 for Finance and Operations

How to Enable/Disable a Form Button with X++

How to create and run the Runbase batch class in D365

Build HTML and send email in D365 FO with X++

Difference between InMemory and TempDB tables in D365 F&O

Conditional Statements in X++

How to apply a package in LCS Dynamics 365 F&O

Customize the standard excel template in D365FO