Understanding SysOperation Framework in D365FO - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Thursday, June 20, 2024

Understanding SysOperation Framework in D365FO

 Understanding SysOperation Framework in D365FO
x




The SysOperation framework in Microsoft Dynamics 365 Finance and Operations (D365FO) is a powerful tool for creating and executing batch processes in a standardized manner. It allows for long-running operations to be handled efficiently without affecting the user interface. Here's a simple explanation of how the framework works and how to implement it.

Common Uses of SysOperation Framework

  1. Data Import/Export: Automate the import or export of large volumes of data.
  2. Complex Calculations: Perform intensive data processing tasks.
  3. Data Cleanup and Maintenance: Identify and remove duplicate or obsolete records.
  4. Integration with External Systems: Synchronize data between D365FO and external systems.
  5. Mass Data Updates: Efficiently update a large number of records.

Synchronous vs. Asynchronous Processing

  • Synchronous Processing: Runs in the same session as the user interface, blocking the UI until the process is complete. Ideal for short-running tasks that need immediate feedback.
  • Asynchronous Processing: Runs in a separate session, allowing the user to continue other tasks. Suitable for long-running operations that do not need immediate feedback.

Implementing the SysOperation Framework

To implement the SysOperation framework, you need three classes: the data contract, the service, and the controller.

Example: Updating Customer Group

1. Contract Class

Defines the parameters to be passed to the service class.

[DataContract]

class SCPCustGroupChangeContract extends SysOperationDataContractBase

{

    CustAccount custNum;

    CustGroupId custGroup;


    [DataMember]

    public CustAccount custNum(CustAccount _custNum = custNum)

    {

        custNum = _custNum;

        return custNum;

    }


    [DataMember]

    public CustGroupId custGroup(CustGroupId _custGroup = custGroup)

    {

        custGroup = _custGroup;

        return custGroup;

    }

}

2. Service Class

Contains the business logic for the batch operation.

class SCPCustGroupChange

{

    CustAccount custNum;

    CustGroupId custGroup;


    protected void initFromContract(SCPCustGroupChangeContract _contract)

    {

        custNum = _contract.custNum();

        custGroup = _contract.custGroup();

    }


    protected void updateCustGroup()

    {

        CustTable cust = CustTable::find(custNum, true);

        if (cust.RecId != 0)

        {

            cust.CustGroup = custGroup;

            cust.update();

        }

    }


    public void run(SCPCustGroupChangeContract _contract)

    {

        this.initFromContract(_contract);

        ttsBegin;

        this.updateCustGroup();

        ttsCommit;

    }

}

3. Controller Class

Initiates the batch operation by creating an instance of the service class and passing the contract parameters.

class SCPCustGroupChangeController extends SysOperationServiceController

{

    public static void main(Args _args)

    {

        SCPCustGroupChangeController controller;

        controller = new SCPCustGroupChangeController(

            classStr(SCPCustGroupChange),

            methodStr(SCPCustGroupChange, run),

            SysOperationExecutionMode::Synchronous

        );

        controller.parmDialogCaption("Change Customer Group");

        controller.startOperation();

    }

}

Creating an Action Menu Item

  1. Create a new Action menu item.
  2. Set the Object Type property to Class.
  3. Set the Object property to SCPCustGroupChangeController.

Summary

The SysOperation framework in D365FO provides a structured approach to creating and executing batch processes. It allows for the separation of data contracts, business logic, and controller logic, making your code modular and easier to manage. Depending on your process requirements, you can choose between synchronous and asynchronous execution modes. This flexibility makes the SysOperation framework a valuable tool for implementing a wide range of batch processing scenarios in Dynamics 365.

Try It Out

To try out the example, follow these steps:

  1. Create the three classes: Contract, Service, and Controller.
  2. Set up the Action menu item.
  3. Run the menu item to see the batch process in action.

By following these steps, you can harness the power of the SysOperation framework to automate and streamline complex processes in D365FO.

About Our Team

Our team is composed of software development and analysis experts who have worked both domestically and internationally:

  • Nghia Song (Mr.) - Technical Architect. With over 6 years of experience in implementing ERP and integration projects.
  • Jone Nguyen (Mr.) - Senior Technical Consultant. With practical experience in 25 E-invoice projects with software systems of businesses both domestically and internationally.
  • Victor (Mr.) - Senior Project Manager.With over 12 years of specialized experience in Dynamics 365 Fno.
  • Lisa Doan (Ms.) – Finance Consultant. A consultant specializing in accounting on Dynamics 365 FO and consolidated accounting systems.

Song Thành NghÄ©a                                                 
Microsoft Dynamics 365 Technical Architect
Mobile/WA: +356 7748 2386 | Web: https://www.songnghia.com/
Zalo: +84 967 324 794 | Mail: nghia@songnghia.com

No comments:

Post a Comment