Tuesday, February 15, 2022

Multithread in sysoperation framework in D365FO

 Hi guys, Today we see the multithread in sys operation. For sys operation we required 4 classes.

Here we need to create two more classes.

1. Controller class.

2. Service class.

From controller class we need to call service class like the same of sys operation. In service class we need to apply group in our table based on requirement and we are using standard classes to send our value to our contract and controller class.

For multithread Controller class we need to create action menu item.

Just check below code.

Multithread Controller class: 

class TestMultiThreadController extends SysOperationServiceController { public ClassDescription defaultCaption() { return 'order creation using multithread'; } public static void main(Args args) { TestMultiThreadController controller = new TestMultiThreadController(); controller.startOperation(); } public void new() { //super(classStr(TestMultiThreadService), //methodStr(TestMultiThreadService, processOperation), //SysOperationExecutionMode::Synchronous); super(); this.parmClassName(classStr(TestMultiThreadService)); this.parmMethodName(methodStr(TestMultiThreadService, processOperation)); this.parmDialogCaption("Batch operation"); } }

--------------------------------------------------------------------------

Multithread Service Class :


class TestMultiThreadService extends SysOperationServiceBase { public void processOperation()//TestContract _contract) { TestCustomer testCustomer;//My table TestMyController controller;//my controller TestMyContract contract;//my contarct BatchHeader batchHeader; BatchInfo batchInfo; SysRecurrenceData sysRecurrenceData = SysRecurrence::defaultRecurrence(); batchHeader = BatchHeader::construct(); controller = new TestMyController(); while select testCustomer group by Filename // 'Filename' my custom field. where testCustomer.Processed == NoYes::No && testCustomer.ErrorInRecord == NoYes::No { sysRecurrenceData = sysRecurrence::setRecurrenceEndAfter(sysRecurrenceData, 1); batchInfo         = controller.batchInfo(); batchInfo.parmCaption(strFmt("order creation for File- %1", testCustomer.FileName)); contract = controller.getDataContractObject();//get my contract class. contract.parmFileName(testCustomer.FileName);// passing my field value. batchHeader.addTask(controller);//Passing my cotroller to the batch. batchHeader.parmRecurrenceData(sysRecurrenceData); batchHeader.save(); } } }

Keep Daxing!!

No comments:

Post a Comment