D365 Batch Jobs
There are two ways to create batch jobs in d365
1) by using sysoperationframework
2) by creating an x++ class that extends RunBaseBatch
-> RunBaseBatch will ‘inherit‘ all of the code, variables, and functionality of the RunBaseBatch class.
3)We have now created the start of a batch job. But there is still a lot of methods we need to add to actually make it work.
4)In order to make the batch job actually do something, there are a number of methods that need to be overridden or implemented from the base class.
5)First Create a main method.
Main Method code is below
public static void main(Args _args) //main method
{
SportsBatch sportsbath=new SportsBatch(); //classname classnamereference=new classname();
sportsbath.parmInBatch(false); //this is optional and It tells the system whether the ‘Run in Batch’ radio button should be set by default or not.
if (sportsbath.prompt()) // prompt causes the dailog form to open
sportsbath.runOperation(); // this method calls the run methodvin our clas
}
6)Specifically, after creating a batch job class, we need to create a action Menu Item, and set the Object Type to ‘Class’, and Object to the name of the class.
7) Create Run Method (The purpose of this method is to perform the task or process that your batch job should do)
internal final class SportsBatch extends RunBaseBatch
{
#define.CurrentVersion(2)
#localmacro.CurrentList
custaccount
#endmacro
DialogField dialogfromdate;
CustAccount custaccount; // Extended Data Type
public static void main(Args _args)
{
SportsBatch sportsbath=new SportsBatch(); //classname classnamereference=new classname();
sportsbath.parmInBatch(false); //this is optional and It tells the system whether the ‘Run in Batch’ radio button should be set by default or not.
if (sportsbath.prompt()) // prompt causes the dailog form to open
sportsbath.runOperation(); // this method calls the run method in our class
}
protected boolean canRunInNewSession() // we overrided this method
{
return false;
}
public Object dialog()
{
DialogRunbase dialog;
//Setup the dialog
dialog = super();
dialog.caption("@MCR12442");
dialogfromdate = dialog.addField(extendedtypestr(custaccount), "cust account number" ); // get value from parameter
dialogfromdate.value('');
return dialog;
}
public boolean getFromDialog()
{
boolean ret;
Sports sports;
ret = super();
custaccount= dialogfromdate.value(); // get value from job parameter
CustCustomerV3Entity custcustomer;
if (!custaccount)
{
info('Custaccount number not found');
}
while select * from custcustomer where custcustomer..CustomerAccount==custaccount
{
info(strFmt("%1 -%2",custcustomer .FullPrimaryAddress,custcustomer .PrimaryContactPhone));
}
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;
}
public static ClassDescription description()
{
return "@MCR12442";
}
}
Comments
Post a Comment