here is the code
Class batch extends runbasebatch
{
public void run()
{
try
{
ttsbegin;
if(this.isinbatch) ///always return false ************************
/// whatever the implementation is
ttsCommit;
}
catch(Exception::Error)
{
ttsabort;
}
catch(Exception::Deadlock)
{
retry;
}
}
public void BatchStarted()
{
BatchJob batchJob;
BatchRetries noOfRetriesOnFailure = 2;
BatchHeader header;
Batch batch;
batch _FixedAssetsBatch; // Class extends RunBaseBatch
BatchInfo processBatchInfo;
SysRecurrenceData sysRecurrenceData;
header = BatchHeader::construct();
select forupdate batch
join batchJob
where batchJob.RecId == batch.BatchJobId
&& batch.ClassNumber == classnum(FixedAssetsBatch)
&& batchJob.Status == BatchStatus::Waiting
&& batch.Company == curext();
if(!batch)
{
_FixedAssetsBatch = new FixedAssetsBatch();
processBatchInfo = _FixedAssetsBatch.batchInfo();
processBatchInfo.parmRetriesOnFailure(noOfRetriesOnFailure);
processBatchInfo.parmCaption(_FixedAssetsBatch.name()); // Description Batch Job
processBatchInfo.parmGroupId('FABatch'); // Batch Gorup
processBatchInfo.parmBatchExecute(NoYes::Yes);
header.addTask(_FixedAssetsBatch);
// Set the recurrence data
sysRecurrenceData = SysRecurrence::defaultRecurrence();
sysRecurrenceData= SysRecurrence::setRecurrenceStartDate(sysRecurrenceData,today());
SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData,DateTimeUtil::addSeconds(DateTimeUtil::utcNow(),30)); // Set range of recurrence
sysRecurrenceData=SysRecurrence::setRecurrenceEndAfter(sysRecurrenceData,1);
// SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::); // Set reccurence pattern
header.parmRecurrenceData(sysRecurrenceData);
// Set the batch alert configurations
header.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::Yes);
header.save();
}
ttsbegin;
select forupdate batchJob
join batch
where batchJob.RecId == batch.BatchJobId
&& batch.ClassNumber == classnum(FixedAssetsBatch);
sysRecurrenceData = batchJob.RecurrenceData;
sysRecurrenceData = conpoke(sysRecurrenceData, 8, [1]);
batchJob.RecurrenceData = sysRecurrenceData;
batchJob.update();
ttscommit;
}
public static void main(Args _args)
{
batch_FixedAssetsBatch = Batch::construct();
_FixedAssetsBatch.BatchStarted();
_FixedAssetsBatch.init();
// _FixedAssetsBatch.parmBatch(_args);
_FixedAssetsBatch.run();
}
}