Scenarion : parameter as minutes and parameter is not taking in batch job so created field in sale parameters and updating in parameter table.
ex : 12.30 and giving parametr 30 minutes i.e 12 before sale sorder should be deleted.
class DeleteSalesOrdersWithNoSaleslinesBatch extends RunBaseBatch
{
Minutes minutes;
DialogField fieldAccount;
#DEFINE.CurrentVersion(1)
#DEFINE.Version1(1)
boolean canGoBatchJournal()
{
return true;
}
protected void new()
{
super();
}
public Object dialog()
{
Minutes numOfMinutes = SalesParameters::find().MinutesAfterCreate;
Dialog dialog = super();
fieldAccount = dialog.addField(extendedTypeStr(Minutes), 'Minutes');
fieldAccount.value(numOfMinutes);
return dialog;
}
public boolean getFromDialog()
{
minutes = fieldAccount.value();
if (minutes != 0)
{
ttsbegin;
SalesParameters parameters = SalesParameters::find(true);
parameters.MinutesAfterCreate = minutes;
parameters.update();
ttscommit;
}
return super();
}
public container pack()
{
//Serializes the current instance of the RunBase class.
return [#CurrentVersion];
}
public boolean runsImpersonated()
{
return true;
}
public boolean unpack(container packedClass)
{
//Deserializes the packedClass parameter value to an instance of the RunBase class.
boolean isSuccessful;
Version version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
{
[version] = packedClass;
isSuccessful = true;
break;
}
default :
return false;
}
return isSuccessful;
}
server static DeleteSalesOrdersWithNoSaleslinesBatch construct()
{
return new DeleteSalesOrdersWithNoSaleslinesBatch();
}
client server static ClassDescription description()
{
return "Deletesalesorderwithnosaleslines";
}
public void deleteSalesOrdersWithNoSalesline()
{
SalesTable salesTable;
SalesLine salesLine;
int ordercount =0;
Minutes numOfMinutes = SalesParameters::find().MinutesAfterCreate;
DateTimeAccepted dateTime = DateTimeUtil::addMinutes(DateTimeUtil::getSystemDateTime(),-numOfMinutes);
ttsbegin;
while select forupdate salesTable
where salesTable.CreatedDateTime <= dateTime
&& salestable.SalesType == SalesType::Sales
notexists join salesLine
where salesLine.SalesId == salesTable.SalesId
{
if(salesTable)
{
ordercount++;
salesTable.delete();
info(strFmt("@USV:Salesoderdeleted", salesTable.SalesId));
}
}
ttscommit;
if(ordercount == 0)
{
info(strfmt("@USV:Nosalesordersavailablefordeletion"));
}
}
void run()
{
#OCCRetryCount
;
try
{
if(USVParameters::autoforceModsEnabled())
{
this.deleteSalesOrdersWithNoSalesline();
}
else
{
info("@USV:AutoForceModenotenabled");
}
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public static void main(Args args)
{
DeleteSalesOrdersWithNoSaleslinesBatch deleteSalesOrderbatch = DeleteSalesOrdersWithNoSaleslinesBatch::construct();
if (deleteSalesOrderbatch.prompt())
{
deleteSalesOrderbatch.run();
}
}
}
ex : 12.30 and giving parametr 30 minutes i.e 12 before sale sorder should be deleted.
class DeleteSalesOrdersWithNoSaleslinesBatch extends RunBaseBatch
{
Minutes minutes;
DialogField fieldAccount;
#DEFINE.CurrentVersion(1)
#DEFINE.Version1(1)
boolean canGoBatchJournal()
{
return true;
}
protected void new()
{
super();
}
public Object dialog()
{
Minutes numOfMinutes = SalesParameters::find().MinutesAfterCreate;
Dialog dialog = super();
fieldAccount = dialog.addField(extendedTypeStr(Minutes), 'Minutes');
fieldAccount.value(numOfMinutes);
return dialog;
}
public boolean getFromDialog()
{
minutes = fieldAccount.value();
if (minutes != 0)
{
ttsbegin;
SalesParameters parameters = SalesParameters::find(true);
parameters.MinutesAfterCreate = minutes;
parameters.update();
ttscommit;
}
return super();
}
public container pack()
{
//Serializes the current instance of the RunBase class.
return [#CurrentVersion];
}
public boolean runsImpersonated()
{
return true;
}
public boolean unpack(container packedClass)
{
//Deserializes the packedClass parameter value to an instance of the RunBase class.
boolean isSuccessful;
Version version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
{
[version] = packedClass;
isSuccessful = true;
break;
}
default :
return false;
}
return isSuccessful;
}
server static DeleteSalesOrdersWithNoSaleslinesBatch construct()
{
return new DeleteSalesOrdersWithNoSaleslinesBatch();
}
client server static ClassDescription description()
{
return "Deletesalesorderwithnosaleslines";
}
public void deleteSalesOrdersWithNoSalesline()
{
SalesTable salesTable;
SalesLine salesLine;
int ordercount =0;
Minutes numOfMinutes = SalesParameters::find().MinutesAfterCreate;
DateTimeAccepted dateTime = DateTimeUtil::addMinutes(DateTimeUtil::getSystemDateTime(),-numOfMinutes);
ttsbegin;
while select forupdate salesTable
where salesTable.CreatedDateTime <= dateTime
&& salestable.SalesType == SalesType::Sales
notexists join salesLine
where salesLine.SalesId == salesTable.SalesId
{
if(salesTable)
{
ordercount++;
salesTable.delete();
info(strFmt("@USV:Salesoderdeleted", salesTable.SalesId));
}
}
ttscommit;
if(ordercount == 0)
{
info(strfmt("@USV:Nosalesordersavailablefordeletion"));
}
}
void run()
{
#OCCRetryCount
;
try
{
if(USVParameters::autoforceModsEnabled())
{
this.deleteSalesOrdersWithNoSalesline();
}
else
{
info("@USV:AutoForceModenotenabled");
}
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public static void main(Args args)
{
DeleteSalesOrdersWithNoSaleslinesBatch deleteSalesOrderbatch = DeleteSalesOrdersWithNoSaleslinesBatch::construct();
if (deleteSalesOrderbatch.prompt())
{
deleteSalesOrderbatch.run();
}
}
}