Create a simple batch job to delete a record and count though runbase
Today we have a requirement to create a simple batch job which helps to delete a record from the table.
=================================================================
//Batch to delete linked tranfser order records where prodid item inventdim doesnot match with the linked transfer order item inventdim id
class AVALinkedTransferOrderCleanUpBatch extends RunBaseBatch
{
QueryRun queryRun;
#DEFINE.CurrentVersion(1)
#OCCRetryCount
public container pack()
{
container pack = conNull();
return [#CurrentVersion] ;
}
public Object dialog()
{
DialogRunbase dialog = super();
return dialog;
}
public boolean getFromDialog()
{
boolean ret;
ret = super();
return ret;
}
/// <summary>
/// Contains the code that does the actual job of the class.
/// </summary>
public void run()
{
InventTransferTable inventTransferTable,inventTransferTableUPD;
InventTransferLine inventTransferLine;
AVAReqLinkedTransferOrder avaReqLinkedTo,avaReqLinkedToDelete,reqTotalLinkedTo,reqAfterDeleteLinkedTO,incorrectLinkedTO ;
ProdTable prodTable;
Integer totalCount;
//Get the count of the transfer order before delete which have different item invent dim ID
select count(RecId) from avaReqLinkedTo
exists join inventTransferTable
where inventTransferTable.TransferId == avaReqLinkedTo.RefId
&& inventTransferTable.TransferStatus ==InventTransferStatus::Created
exists join inventTransferLine
where inventTransferLine.TransferId == inventtransfertable.TransferId
exists join prodTable
where prodTable.ProdId == avaReqLinkedTo.ProdId
&& prodTable.InventDimId != inventTransferLine.InventDimId;
select count(RecId) from reqTotalLinkedTo;
info(strFmt("@AVAExtension:AVABeforeDeletion_InfoMsg", reqTotalLinkedTo.RecId, avaReqLinkedTo.RecId));
ttsbegin;
//Delete the transfer order from the production order whos item inventdim is not matched
delete_from avaReqLinkedToDelete
exists join inventTransferTableUPD
where inventTransferTableUPD.TransferId == avaReqLinkedToDelete.RefId
&& inventTransferTableUPD.TransferStatus == InventTransferStatus::Created
exists join inventTransferLine
where inventTransferLine.TransferId == inventTransferTableUPD.TransferId
exists join prodTable
where prodTable.ProdId == avaReqLinkedToDelete.ProdId
&& prodTable.InventDimId != inventTransferLine.InventDimId;
ttscommit;
select count(RecId) from reqAfterDeleteLinkedTO;
select count(RecId) from incorrectLinkedTO
exists join inventTransferTable
where inventTransferTable.TransferId == incorrectLinkedTO.RefId
&& inventTransferTable.TransferStatus ==InventTransferStatus::Created
exists join inventTransferLine
where inventTransferLine.TransferId == inventtransfertable.TransferId
exists join prodTable
where prodTable.ProdId == incorrectLinkedTO.ProdId
&& prodTable.InventDimId != inventTransferLine.InventDimId;
info(strFmt("@AVAExtension:AVAPostDeletion_InfoMsg", reqAfterDeleteLinkedTO.RecId,incorrectLinkedTO.recid));
}
/// <summary>
/// Determines whether the batch task is run on the server or on a client.
/// </summary>
/// <returns>
/// true if the task is run on the server; otherwise, false.
/// </returns>
/// <remarks>
/// Your classes that extend <c>RunBaseBatch</c> must override the <c>runsImpersonated</c> method and
/// return false, if you want those tasks to run on a client.
/// </remarks>
public boolean runsImpersonated()
{
return true;
}
/// <summary>
/// Determines whether to add a Select button to the dialog box.
/// </summary>
/// <returns>
/// Always returns true.
/// </returns>
/// <remarks>
/// If you click this button, it will show the query form. Therefore, the <c>queryRun</c> method has to
/// return a valid <c>queryRun</c> value.
/// </remarks>
public boolean showQueryValues()
{
return true;
}
public boolean unpack(container _packedClass)
{
Version version = RunBase::getVersion(_packedClass);
container packedQuery;
switch (version)
{
case #CurrentVersion :
[version, packedQuery] = _packedClass;
break;
default:
return false;
}
return true;
}
public static AVALinkedTransferOrderCleanUpBatch construct()
{
return new AVALinkedTransferOrderCleanUpBatch();
}
Static public ClassDescription description()
{
return "@AVAExtension:AVALinkedTransferOrderCleanUpBatch_Description";
}
client static void main(Args args)
{
AVALinkedTransferOrderCleanUpBatch obj = AVALinkedTransferOrderCleanUpBatch::construct();
obj.parmInBatch(true);
obj.getLast();
obj.caption();
if (obj.prompt())
{
obj.runOperation();
}
}
protected boolean canRunInNewSession()
{
return false;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected boolean canGoBatchJournal()
{
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean canGoBatch()
{
return true;
}
}
========================================================================
Comments
Post a Comment