Difference between RunBase and RunBaseBatch class – AX 2012 Or Dynamics 365 F&O
RunBase: To create a job or an Action class – a program that carries out processes, such as accepting parameters from the user and then updating records in the database – you use the RunBase framework.
The framework is implemented by the RunBase application class and supplies many features, which include the following:
· Query
· dialog, with the persistence of the last values entered by the user
· Validate
The RunBase application framework runs or batches an operation.
An operation is a unit of work, such as the posting of a sales order or calculation of a master schedule.
The RunBase framework uses the Dialog framework to prompt a user for data input.
It uses the SysLastValue framework to persist usage data and the Operation Progress framework to show operation progress.
The RunBase class is a framework for classes that need a dialog for user interaction and that need the dialog values to be saved per user.
RunBaseBatch: You can design your own batch job by extending the RunBaseBatch class. You can also write code to schedule the batch to run. The batch runs on the Application Object Server (AOS)
RunBaseBatch is an extension of RunBase – it adds a support for batch processing.
SysOperation framework is a newer framework replacing RunBase (and its extensions such as RunBaseBatch).
Create a Runbase batch class
Recently got a requirement to create a run base batch for posting inventory journals.So, I created below class.
Please change the code according to your requirement.
Step 1 – Copy and paste the below code in a new class
Step 2 – Create a new action button and attach the class to it.
Step 3 – Add the action button to a module. In my case I added it to the Inventory Management -> Periodic area.
/// Created this class for posting open inventory journals
class InventoryJournalsPostings extends RunBaseBatch
{
QueryRun gQueryRun;
#define.CurrentVersion(1)
/// <summary>
/// Construct the class
/// </summary>
/// <returns>Return the class object</returns>
public server static InventoryJournalsPostings construct()
{
return new InventoryJournalsPostings();
}
/// <summary>
/// </summary>
/// <returns>Return the class desc</returns>
public client server static ClassDescription description()
{
return “Inventory Journals Posting”;
}
/// <summary>
/// </summary>
/// <returns>Whether the class can be used in a batch task</returns>
protected boolean canGoBatchJournal()
{
return true;
}
/// <summary>
/// <returns></returns>
public container pack()
{
container pack = conNull();
if (gQueryRun)
{
pack = gQueryRun.pack();
}
return [#CurrentVersion] + [pack];
}
/// <summary>
/// </summary>
/// <param name = “packedClass”></param>
/// <returns></returns>
public boolean unpack(container _packedClass)
{
boolean ret = false;
int version = RunBase::getVersion(_packedClass);
container packedQuery = conNull();
switch (version)
{
case #CurrentVersion:
[version, packedQuery] = _packedClass;
if (SysQuery::isPackedOk(packedQuery))
{
gQueryRun = new QueryRun(packedQuery);
ret = true;
}
break;
default:
ret = false;
}
return ret;
}
/// <summary>
/// Allows the class go batch
/// </summary>
/// <returns>Return the result</returns>
public boolean canGoBatch()
{
return true;
}
/// <summary>
/// </summary>
/// <returns>Return the true result</returns>
public boolean runsImpersonated()
{
return true;
}
/// <summary>
/// Doesn’t allows the class run in the new session
/// </summary>
/// <returns>Return the result</returns>
protected boolean canRunInNewSession()
{
return true;
}
/// <summary>
/// </summary>
/// <returns></returns>
public boolean showQueryValues()
{
return true;
}
/// <summary>
/// </summary>
/// <returns></returns>
public QueryRun queryRun()
{
return gQueryRun;
}
/// <summary>
/// </summary>
public void initQueryRun()
{
Query query = new Query();
QueryBuildDataSource inventJournalTableDS;
QueryBuildRange inventJournalStatus;
QueryBuildRange inventJournalStatusRange;
inventJournalTableDS = query.addDataSource(tableNum(InventJournalTable));
inventJournalStatus = inventJournalTableDS.addRange(fieldNum(InventJournalTable, Posted));
inventJournalStatus = inventJournalTableDS.addRange(fieldNum(InventJournalTable, JournalId));
gQueryRun = new QueryRun(query);
gQueryRun.saveUserSetup(true);
}
/// <summary>
/// </summary>
/// <param name = “_args”>The specified arguments</param>
public static void main(Args _args)
{
InventoryJournalsPostings InventoryJournalsPostings = InventoryJournalsPostings::construct();
InventoryJournalsPostings.getLast();
InventoryJournalsPostings.caption();
InventoryJournalsPostings.initQueryRun();
if (InventoryJournalsPostings.prompt())
{
InventoryJournalsPostings.run();
}
}
/// <summary>
/// Post open inventory journals
/// </summary>
public void run()
{
InventJournalTable inventJournalTable;
//Query query = gQueryRun.query();
while (gQueryRun.next())
{
inventJournalTable = gQueryRun.get(tableNum(inventJournalTable));
if (inventJournalTable.Posted == NoYes::No)
{
JournalCheckPost journalCheckPost;
journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
try
{
ttsbegin;
if(journalCheckPost.validate())
{
journalCheckPost.run();
}
ttscommit;
}
catch
{
info(infolog.text());
}
}
}
}
}