Dieser Beitrag bezieht sich auf die Version:
Dynamics AX 2012
Dynamics AX 2012
|
|
@Magnus You should use the batchHeader.addRunTimeTask method for your requirement. |
|
|
|
|
|
|
|
Dieser Beitrag bezieht sich auf die Version:
Dynamics AX 2012
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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(); }