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:
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
Post a Comment