SysOperation Framework D365 F&O - Song Nghia - #Open To Relocate

Dynamics 365 Outsourcing Service

Thứ Bảy, 2 tháng 4, 2022

SysOperation Framework D365 F&O

SysOperation Framework D365 F&O

Nghia Song -  Microsoft Dynamics 365 Technical Consultant

Nghia Song

Tel - WhatsApp: +84967324794

Email: songnghia.uit@gmail.com

SysOperation Framework D365 F&O 

Thursday, June 17, 2021 9:35 PM 

SysOperation framework permits batch logic to be written in a manner that helps  running operations interactively, through the Dynamics batch server. So in this  post i am going to tell about How to code batch using SysOperation Framework in  D365 F&O

SysOperation implements the MVC (Model–View–Controller) design pattern, with  the isolation of Parameters (Model), Dialog (View), and Service (Controller), for  the code that’s executed. Batch using SysOperation Framework in D365 F&O  makes the system more efficient. 

The important objects of the SysOperation framework are outlined beneath: 

Service 

Service class extends from the SysOperationServiceBase class and incorporates  the business logic for the batch operation. Developers typically have a tendency  so as to add the business logic in controller classes, which violates the Single  accountability precept. 

Data Contract 

Data contract class is the model class defining attributes wanted for batch  operations. These attributes are provided by the user, in a dialog.  DataContractAttribute attribute is required for the class and the properties  methods requires DataMemberAttribute attribute. 

Controller 

Controller class extends from the SysOperationServiceController class. It holds  details about the batch operation like execution mode, present dialog or progress  bar and many others. It directs the batch operation. 

UI Builder 

UI Builder class extends from SysOperationAutomaticUIBuilder class and is used  for adding customized behavior to dialog / dialog fields dynamically constructed  by the SysOperation framework. 

On this blog post, I’ll cover three totally different scenarios (in a sequential   AX 365 Page 1 

On this blog post, I’ll cover three totally different scenarios (in a sequential  method) for creating batch using SysOperation framework in D365 F&O

Scenario 1: Creating a simple batch 

To Create a simple batch we need Controller class, Service class and Menu Item  to run it. 

AX 365 Page 2 

Controller class 

public class TestControllerClass extends SysOperationServiceController

 public void new() 

 { 

 AX 365 Page 3 

 

 super(); 

  

 this.parmClassName(classStr(TestServiceClass)); 

 this.parmMethodName(methodStr(TestServiceClass, processOperation));

  

10 

 this.parmDialogCaption("Batch Dialog Title"); 

11 

 

12 

13 

 public ClassDescription caption() 

14 

 { 

15 

 return "Batch Task Description"

16 

 

17 

18 

 public static void main(Args args) 

19 

 

20 

 TestControllerClass controller; 

21 

  

22 

 controller = new TestControllerClass(); 

23 

 controller.startOperation(); 

24 

 } 

25 

26 

Service class 

public class TestServiceClass extends SysOperationServiceBase

  

 public void processOperation() 

 

 //Input any business process logic that need to be scheduled on batch

 info ("Running Batch Operation"); 

 } 

10 

Menu Item 

Name: TestSysOperationBatchMenu 

Type: Action menu item 

Object type: Class 

Object: TestControllerClass 

Then add created menu item to some Menu like Accounts payable for testing as  shown below. 

 AX 365 Page 4 

Scenario 2: Add custom parameters for batch  operation 

You can add custom parameters using parmMethods to Data contract class.  AX 365 Page 5 

Output can be seen in Batch job Logs 

Controller class 

public class TestControllerClass extends SysOperationServiceController

 public void new() 

 { 

 super(); 

  

 AX 365 Page 6 

  

 this.parmClassName(classStr(TestServiceClass)); 

 this.parmMethodName(methodStr(TestServiceClass, processOperation));

  

10 

 this.parmDialogCaption("Batch Dialog Title"); 

11 

 

12 

13 

 public ClassDescription caption() 

14 

 

15 

 return "Batch Task Description"

16 

 } 

17 

18 

 public static void main(Args args) 

19 

 { 

20 

 TestControllerClass controller; 

21 

  

22 

 controller = new TestControllerClass(); 

23 

 controller.startOperation(); 

24 

 

25 

26 

Service class 

public class TestServiceClass extends SysOperationServiceBase

  

 public void processOperation(TestContractClass _contract)

 { 

 //Input any business process logic that need to be scheduled on batch

 info ("Running Batch Operation"); 

  

10 

 info ("Date: " + date2Str 

11 

 (_contract.parmDate(), 

12 

 213, 

13 

 DateDay::Digits2, 

14 

 DateSeparator::Dot, 

15 

 DateMonth::Long, 

16 

 DateSeparator::Dot, 

17 

 DateYear::Digits4)); 

18 

  

19 

 info ("Text: " + _contract.parmText()); 

20 

 } 

21 

22 

Data Contract class 

[DataContractAttribute] 

public class TestContractClass 

 TransDate dateValue; 

 Description255 textValue; 

 [DataMemberAttribute, 

 SysOperationLabelAttribute('Date'), 

10 

 SysOperationHelpTextAttribute('Enter a date in past'), 11 

 SysOperationDisplayOrderAttribute('1')] 

12 

 public TransDate parmDate(TransDate _dateValue = dateValue) 

 AX 365 Page 7 

12 

 public TransDate parmDate(TransDate _dateValue = dateValue) 13 

 

14 

 dateValue = _dateValue; 

15 

 return dateValue; 

16 

 

17 

18 

 [DataMemberAttribute, 

19 

 SysOperationLabelAttribute('Text'), 

20 

 SysOperationHelpTextAttribute('Type some text'), 

21 

 SysOperationDisplayOrderAttribute('2')] 

22 

 public Description255 parmText(Description255 _textValue = textValue) 23 

 

24 

 textValue = _textValue; 

25 

 return textValue; 

26 

 

27 

28 

Menu Item 

Name: TestSysOperationBatchMenu 

Type: Action menu item 

Object type: Class 

Object: TestControllerClass 

Scenario 3: Add custom validation to dialog fields 

On Parameter dialog many times inputs needs to be validated according to  business logic. This can be achieved by using UI Builder class. It helps in creation  of dynamic/interactive parameters. 

 AX 365 Page 8 

Controller class 

public class TestControllerClass extends SysOperationServiceController

 public void new() 

 

 super(); 

  

 AX 365 Page 9 

  

 this.parmClassName(classStr(TestServiceClass)); 

 this.parmMethodName(methodStr(TestServiceClass, processOperation));

  

10 

 this.parmDialogCaption("Batch Dialog Title"); 

11 

 

12 

13 

 public ClassDescription caption() 

14 

 

15 

 return "Batch Task Description"

16 

 } 

17 

18 

 public static void main(Args args) 

19 

 { 

20 

 TestControllerClass controller; 

21 

  

22 

 controller = new TestControllerClass(); 

23 

 controller.startOperation(); 

24 

 

25 

26 

Service class 

public class TestServiceClass extends SysOperationServiceBase

  

 public void processOperation(TestContractClass _contract)

 { 

 //Input any business process logic that need to be scheduled on batch

 info ("Running Batch Operation"); 

  

10 

 info ("Date: " + date2Str 

11 

 (_contract.parmDate(), 

12 

 213, 

13 

 DateDay::Digits2, 

14 

 DateSeparator::Dot, 

15 

 DateMonth::Long, 

16 

 DateSeparator::Dot, 

17 

 DateYear::Digits4)); 

18 

  

19 

 info ("Text: " + _contract.parmText()); 

20 

 } 

21 

22 

Data Contract class 

[DataContractAttribute, 

SysOperationContractProcessingAttribute(classStr(TestUIBuilderClass))]

public class TestContractClass 

 TransDate dateValue; 

 Description255 textValue; 

 [DataMemberAttribute, 

10 

 SysOperationLabelAttribute('Date'), 

11 

 SysOperationHelpTextAttribute('Enter a date in past'), 

12 

 SysOperationDisplayOrderAttribute('1')] 

 AX 365 Page 10 

12 

 SysOperationDisplayOrderAttribute('1')] 

13 

 public TransDate parmDate(TransDate _dateValue = dateValue) 14 

 { 

15 

 dateValue = _dateValue; 

16 

 return dateValue; 

17 

 

18 

19 

 [DataMemberAttribute, 

20 

 SysOperationLabelAttribute('Text'), 

21 

 SysOperationHelpTextAttribute('Type some text'), 

22 

 SysOperationDisplayOrderAttribute('2')] 

23 

 public Description255 parmText(Description255 _textValue = textValue) 24 

 

25 

 textValue = _textValue; 

26 

 return textValue; 

27 

 

28 

29 

UI Builder class 

public class TestUIBuilderClass extends SysOperationAutomaticUIBuilder

 DialogField dateField; 

  

 public void postBuild() 

 { 

 super(); 

  

10 

 // get references to dialog controls after creation 

11 

 dateField = this.bindInfo().getDialogField(this.dataContractObject(), 12 

 methodStr(TestContractClass, parmDate)); 13 

 } 

14 

15 

 public void postRun() 

16 

 { 

17 

 super(); 

18 

  

19 

 // register overrides for form control events 

20 

 dateField.registerOverrideMethod(methodstr(FormDateControl, validate), 21 

 methodstr(TestUIBuilderClass, validateDate), this); 

22 

 } 

23 

24 

 public boolean validateDate(FormDateControl _dateControl) 25 

 

26 

 if (_dateControl.dateValue() > today()) 

27 

 { 

28 

 error("Please select a valid date"); 

29 

 return false

30 

 } 

31 

  

32 

 return true

33 

 } 

34 

35 

Menu Item 

Name: TestSysOperationBatchMenu 

 AX 365 Page 11 

Type: Action menu item 

Object type: Class 

Object: TestControllerClass 

So you can use any of the shared scenarios, according to requirement to facilitate  your customization. 

From <https://daxtechie.com/batch-using-sysoperation-framework/>   Ref: https://www.blogger.com/blog/post/edit/997671370297380642/3179422713652233212

 Dynamics 365 FO - Classes with data - Run Base Framework

 AX 365 Page 12