SysOperation Framework D365 F&O - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Saturday, April 2, 2022

SysOperation Framework D365 F&O

🧩 Introduction to SysOperation Framework in D365 F&O


The SysOperation Framework allows you to write batch jobs in a clean, modular way using the MVC pattern:

Component Description
Model (Data Contract) Stores input parameters
View (Dialog / UI Builder) Displays the user interface
Controller Launches the operation and defines the batch process
Service Contains the business logic

📘 Scenario 1: Simple Batch Without Parameters

✅ Controller Class

public class TestControllerClass extends SysOperationServiceController
{
    public void new()
    {
        super();
        this.parmClassName(classStr(TestServiceClass));
        this.parmMethodName(methodStr(TestServiceClass, processOperation));
        this.parmDialogCaption("Batch Dialog Title");
    }

    public ClassDescription caption()
    {
        return "Batch Task Description";
    }

    public static void main(Args args)
    {
        TestControllerClass controller = new TestControllerClass();
        controller.startOperation();
    }
}

✅ Service Class

public class TestServiceClass extends SysOperationServiceBase
{
    public void processOperation()
    {
        info("Running Batch Operation");
    }
}

✅ Menu Item

  • Name: TestSysOperationBatchMenu
  • Type: Action
  • Object type: Class
  • Object: TestControllerClass

📘 Scenario 2: Batch With Input Parameters

✅ Data Contract Class

[DataContractAttribute]
public class TestContractClass
{
    TransDate dateValue;
    Description255 textValue;

    [DataMemberAttribute,
     SysOperationLabelAttribute('Date'),
     SysOperationHelpTextAttribute('Enter a date in the past'),
     SysOperationDisplayOrderAttribute('1')]
    public TransDate parmDate(TransDate _dateValue = dateValue)
    {
        dateValue = _dateValue;
        return dateValue;
    }

    [DataMemberAttribute,
     SysOperationLabelAttribute('Text'),
     SysOperationHelpTextAttribute('Enter some text'),
     SysOperationDisplayOrderAttribute('2')]
    public Description255 parmText(Description255 _textValue = textValue)
    {
        textValue = _textValue;
        return textValue;
    }
}

✅ Updated Service Class

public class TestServiceClass extends SysOperationServiceBase
{
    public void processOperation(TestContractClass _contract)
    {
        info("Running Batch Operation");

        info("Date: " + date2Str(_contract.parmDate(),
          DateDay::Digits2,
          DateSeparator::Dot,
          DateMonth::Long,
          DateSeparator::Dot,
          DateYear::Digits4));

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

📘 Scenario 3: Input Validation with UI Builder

✅ UI Builder Class

public class TestUIBuilderClass extends SysOperationAutomaticUIBuilder
{
    DialogField dateField;

    public void postBuild()
    {
        super();
        dateField = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TestContractClass, parmDate));
    }

    public void postRun()
    {
        super();
        dateField.registerOverrideMethod(
            methodStr(FormDateControl, validate),
            methodStr(TestUIBuilderClass, validateDate),
            this);
    }

    public boolean validateDate(FormDateControl _dateControl)
    {
        if (_dateControl.dateValue() > today())
        {
            error("Please select a valid date");
            return false;
        }

        return true;
    }
}

✅ Updated Data Contract Class

[DataContractAttribute,
 SysOperationContractProcessingAttribute(classStr(TestUIBuilderClass))]
public class TestContractClass
{
    TransDate dateValue;
    Description255 textValue;

    [DataMemberAttribute,
     SysOperationLabelAttribute('Date'),
     SysOperationHelpTextAttribute('Enter a date in the past'),
     SysOperationDisplayOrderAttribute('1')]
    public TransDate parmDate(TransDate _dateValue = dateValue)
    {
        dateValue = _dateValue;
        return dateValue;
    }

    [DataMemberAttribute,
     SysOperationLabelAttribute('Text'),
     SysOperationHelpTextAttribute('Enter some text'),
     SysOperationDisplayOrderAttribute('2')]
    public Description255 parmText(Description255 _textValue = textValue)
    {
        textValue = _textValue;
        return textValue;
    }
}

✅ Menu Item (for all scenarios)

  • Name: TestSysOperationBatchMenu
  • Type: Action
  • Object type: Class
  • Object: TestControllerClass

🎯 Summary

Scenario Use Case
1. Simple Run logic without parameters
2. With Parameters Accept input values
3. With Validation Validate input before execution

No comments:

Post a Comment