Create a batch job to zero delete pending price
Today we have a requirement to delete the zero pending price for that we have created a simple batch job with the contract filter and validate also
==========================================================================
/// <summary>
/// Creates pending price batch job to delete record which have the zero price in pending price
/// </summary>
class AVADeletePendingPriceBatch extends RunBaseBatch implements BatchRetryable
{
QueryRun queryRun;
DialogField dialogFieldCostingVersion;
DialogField dialogFieldFromDate;
CostingVersionId fromCostingVersion;
TransDate fromDateDialog;
InventItemPriceSim ItemPriceSim, deleteItemPriceSim;
#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
fromCostingVersion,
fromDateDialog
#Endmacro
void new()
{
super();
queryRun = new QueryRun(querystr(AVADeletePendingPriceQuery));
}
public container pack()
{
return [#CurrentVersion, #CurrentList, queryRun.pack()];
}
public boolean unpack(container packedClass)
{
container packedQuery;
Integer version = RunBase::getVersion(packedClass);
switch (version)
{
case #CurrentVersion :
[version, #CurrentList, packedQuery] = packedClass;
if (packedQuery)
{
queryRun = new QueryRun(packedQuery);
}
break;
default :
return false;
}
return true;
}
/// <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 QueryRun queryRun()
{
return queryRun;
}
public static AVADeletePendingPriceBatch construct()
{
return new AVADeletePendingPriceBatch();
}
Static public ClassDescription description()
{
return "@AVAExtension:AVADeletePendingPrice";
}
client static void main(Args args)
{
AVADeletePendingPriceBatch obj = AVADeletePendingPriceBatch::construct();
obj.parmInBatch(true);
obj.getLast();
obj.caption();
obj.initParmDefault();
if (obj.prompt())
{
obj.runOperation();
}
}
protected boolean canRunInNewSession()
{
return false;
}
public Object dialog()
{
dialogGroup dialogGroup;
DialogRunbase dialog = super();
dialogGroup = dialog.addGroup("@SYS7764");
dialogFieldCostingVersion = dialog.addFieldValue(extendedTypeStr(CostingVersionId), fromCostingVersion, "@SYS103444");
dialogFieldFromDate = dialog.addFieldValue(extendedTypeStr(TransDate), fromDateDialog, "@SYS24050");
dialogGroup.columns(2);
return dialog;
}
public boolean getFromDialog()
{
boolean ret = super();
fromCostingVersion = dialogFieldCostingVersion.value();
fromDateDialog = dialogFieldFromDate.value();
return ret;
}
public boolean validate(Object calledFrom = null)
{
boolean ret = super();
if (!fromCostingVersion)
{
ret = checkFailed("@AVAExtension:AVADeletePendingPrice_InfoMsg");
}
return ret;
}
public void run()
{
if (!this.validate())
{
throw error("@AVAExtension:AVADeletePendingPrice_InfoMsg");
}
if(fromDateDialog)
{
this.deletePendingPriceWithDate();
}
else
{
this.deletePendingPriceWithoutDate();
}
}
/// <summary>
/// Specifies if the batch task is retryable for transient exceptions or not.
/// </summary>
/// <returns>
/// If true is returned, the batch task is retryable, otherwise it is not.
/// </returns>
[Hookable(false)]
public boolean isRetryable()
{
return true;
}
/// <summary>
/// If a user select the from date from dialog this method compare the record and if found delete it from table.
/// </summary>
protected void deletePendingPriceWithDate()
{
queryRun = this.queryRun();
while (queryRun.next())
{
ItemPriceSim = queryRun.get(tableNum(InventItemPriceSim));
select deleteItemPriceSim
where deleteItemPriceSim.RecId == ItemPriceSim.RecId
&& deleteItemPriceSim.Price == 0.00000
&& deleteItemPriceSim.VersionId == fromCostingVersion
&& deleteItemPriceSim.FromDate == fromDateDialog;
if(deleteItemPriceSim)
{
deleteItemPriceSim.skipDeleteActions(false);
deleteItemPriceSim.selectForUpdate(true);
ttsbegin;
deleteItemPriceSim.delete();
ttscommit;
}
}
}
/// <summary>
/// If a user select the costing versions and date remain blanks.. if record found delete it from table.
/// </summary>
protected void deletePendingPriceWithoutDate()
{
queryRun = this.queryRun();
while (queryRun.next())
{
ItemPriceSim = queryRun.get(tableNum(InventItemPriceSim));
select deleteItemPriceSim
where deleteItemPriceSim.RecId == ItemPriceSim.RecId
&& deleteItemPriceSim.Price == 0.00000
&& deleteItemPriceSim.VersionId == fromCostingVersion;
if(deleteItemPriceSim)
{
deleteItemPriceSim.skipDeleteActions(false);
deleteItemPriceSim.selectForUpdate(true);
ttsbegin;
deleteItemPriceSim.delete();
ttscommit;
}
}
}
}
======================================================================
Comments
Post a Comment