Die nachstehenden Code-Snippets sollen zeigen, wir man mit Hilfe der BatchHeader-Klasse Stapelverarbeitungsaufträge erstellen kann.
Beispiele für ein RunBaseBatch-Konstrukt
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3;
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
batchTask3 = Tutorial_RunbaseBatch::construct();
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(batchTask3);
//save the batch
batchHeader.save();
}
Möchte man sicherstellen, daß die einzelnen Aufgaben in einer bestimmten Reihenfolge abgearbeitet werden oder zwischen Abhängigkeiten erzeugen, so kann man dies wie folgt tun:
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3;
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
batchTask3 = Tutorial_RunbaseBatch::construct();
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(batchTask3);
//define a dependency between the batch tasks
batchHeader.addDependency(batchTask2, batchTask1, BatchDependencyStatus::Finished);
batchHeader.addDependency(batchTask3, batchTask2, BatchDependencyStatus::Finished);
//save the batch
batchHeader.save();
}
Natürlich kann man auch Warnungen einrichten...
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3;
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
batchTask3 = Tutorial_RunbaseBatch::construct();
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(batchTask3);
// Set the batch alert configurations
batchHeader.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::Yes);
//save the batch
batchHeader.save();
}
...oder eine Geplante Startzeit parametrieren:
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3;
#define.11pm('23:00')
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
batchTask3 = Tutorial_RunbaseBatch::construct();
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(batchTask3);
// Set scheduled start date/time
batchHeader.parmStartDateTime(DateTimeUtil::newDateTime(systemDateGet(), str2time(#11pm), DateTimeUtil::getUserPreferredTimeZone()));
//save the batch
batchHeader.save();
}
Und selbstverständlich kann man auch die Wiederholungen steuern:
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3;
SysRecurrenceData SysRecurrenceData;
#define.11pm('23:00')
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
batchTask3 = Tutorial_RunbaseBatch::construct();
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(batchTask3);
// Set the recurrence data to execute daily 11 pm
sysRecurrenceData = SysRecurrence::defaultRecurrence();
sysRecurrenceData = SysRecurrence::setRecurrenceStartDateTime(
sysRecurrenceData,
DateTimeUtil::newDateTime(systemDateGet(),str2time(#11pm),DateTimeUtil::getUserPreferredTimeZone()));
sysRecurrenceData = SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
sysRecurrenceData = SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Day,1);
batchHeader.parmRecurrenceData(sysRecurrenceData);
//save the batch
batchHeader.save();
}
Beispiel für ein SysOperation-Konstrukt
Alles was für ein RunBaseBatch-Konstrukt möglich ist, ist auch für das Sysperation-Framework machbar. Hier muss man lediglich darauf achten, des SysOperationExecutionMode korrekt zu setzen:
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
SysOperationServiceController controller1, controller2, controller3;
TutorialSysOperationDataContract dataContract1;
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks (SysOperation)");
//create instances of the classes to use as batch tasks
controller1 = new SysOperationServiceController(
classStr(TutorialSysOperationService),
methodStr(TutorialSysOperationService, runService),
SysOperationExecutionMode::Synchronous);
controller1.parmLoadFromSysLastValue(false); // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
dataContract1 = controller1.getDataContractObject();
dataContract1.parmCustAccount("US-004");
controller2 = new SysOperationServiceController(
classStr(TutorialSysOperationService),
methodStr(TutorialSysOperationService, runService),
SysOperationExecutionMode::Synchronous);
controller2.parmLoadFromSysLastValue(false); // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
dataContract1 = controller2.getDataContractObject();
dataContract1.parmCustAccount("US-005");
controller3 = new SysOperationServiceController(
classStr(TutorialSysOperationService),
methodStr(TutorialSysOperationService, runService),
SysOperationExecutionMode::Synchronous);
controller3.parmLoadFromSysLastValue(false); // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
dataContract1 = controller3.getDataContractObject();
dataContract1.parmCustAccount("US-006");
//add the batch tasks to the batch header
batchHeader.addTask(controller1);
batchHeader.addTask(controller2);
batchHeader.addTask(controller3);
//save the batch
batchHeader.save();
}
Kombiniertes Beispiel
Und natürlich ist es auch möglich, RunBaseBatch und SysOperation in einem Stapelverarbeitungsauftrag zu kombinieren:
static void createBatchWithMultipletasks(Args _args)
{
BatchHeader batchHeader;
Tutorial_RunbaseBatch batchTask1, batchTask2;
TutorialSysOperationServiceController controller1;
TutorialSysOperationDataContract dataContract1;
//create batch header
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("Example of a batch job with multiple tasks (RunBaseBatch and SysOperation)");
//create instances of the classes to use as batch tasks
batchTask1 = Tutorial_RunbaseBatch::construct();
batchTask2 = Tutorial_RunbaseBatch::construct();
controller1 = new TutorialSysOperationServiceController(
classStr(TutorialSysOperationService),
methodStr(TutorialSysOperationService, runService),
SysOperationExecutionMode::Synchronous);
controller1.parmLoadFromSysLastValue(false); // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
dataContract1 = controller1.getDataContractObject();
dataContract1.parmCustAccount("US-004");
//add the batch tasks to the batch header
batchHeader.addTask(batchTask1);
batchHeader.addTask(batchTask2);
batchHeader.addTask(controller1);
//save the batch
batchHeader.save();
}
Dieser Beitrag bezieht sich auf die Version: Dynamics AX 2012
We have a scenario where we by code create mutiple batch tasks at runtime.
- We have a "main"-task that in each batch run gathers data to be processed.
- The case is that we want to have one batchtask per a ProjectId.
But after the batch is finished all the individual ProjectId-tasks are still there in the batch job.
The next time the "main"-task is fired there should be no batch tasks in the batchjob. Because there should be a new set of ProjectId-batchtasks created based on what data that exist in the database.
The same batchjob is used over and over again due to a scheduled recurrency.
What is the proper way to "clean up" the batch task list before the new batchrun occur?
We have a scenario where we by code create mutiple batch tasks at runtime.
- We have a "main"-task that in each batch run gathers data to be processed.
- The case is that we want to have one batchtask per a ProjectId.
But after the batch is finished all the individual ProjectId-tasks are still there in the batch job.
The next time the "main"-task is fired there should be no batch tasks in the batchjob. Because there should be a new set of ProjectId-batchtasks created based on what data that exist in the database.
The same batchjob is used over and over again due to a scheduled recurrency.
What is the proper way to "clean up" the batch task list before the new batchrun occur?
Keyur
21.01.2022 00:57 | #3
@Magnus
You should use the batchHeader.addRunTimeTask method for your requirement.
Diese Webseite verwendet Cookies, um Benutzern einen besseren Service anzubieten. Wenn Sie weiterhin auf der Seite bleiben, stimmen Sie der Verwendung von Cookies zu.
Mehr dazu
Die nachstehenden Code-Snippets sollen zeigen, wir man mit Hilfe der BatchHeader-Klasse Stapelverarbeitungsaufträge erstellen kann.
Beispiele für ein RunBaseBatch-Konstrukt
Möchte man sicherstellen, daß die einzelnen Aufgaben in einer bestimmten Reihenfolge abgearbeitet werden oder zwischen Abhängigkeiten erzeugen, so kann man dies wie folgt tun:
Natürlich kann man auch Warnungen einrichten...
...oder eine Geplante Startzeit parametrieren:
Und selbstverständlich kann man auch die Wiederholungen steuern:
Beispiel für ein SysOperation-Konstrukt
Alles was für ein RunBaseBatch-Konstrukt möglich ist, ist auch für das Sysperation-Framework machbar. Hier muss man lediglich darauf achten, des SysOperationExecutionMode korrekt zu setzen:
Kombiniertes Beispiel
Und natürlich ist es auch möglich, RunBaseBatch und SysOperation in einem Stapelverarbeitungsauftrag zu kombinieren: