Simple way to understand SysOperation Framework in D365FO

The SysOperation framework in Microsoft Dynamics 365 is a powerful framework that provides a standardized way to create and execute batch processes. It allows us to define and execute long-running operations in a controlled and efficient manner. Here are some possible uses of the SysOperation framework in D365:

  • Data import/export: You can use the SysOperation framework to create batch processes for importing or exporting large volumes of data. For example, you can create a batch job that imports customer data from an external system into Dynamics 365 or exports sales data from Dynamics 365 to an external reporting system.
  • Complex calculations: The SysOperation framework can be used to perform complex calculations or data transformations. For instance, you can create a batch process that calculates sales commissions based on predefined rules and updates the relevant records in Dynamics 365.
  • Data cleanup and maintenance: The SysOperation framework can be utilized to perform data cleanup and maintenance tasks. For example, you can create a batch job that identifies and removes duplicate or obsolete records, updates data based on specific criteria, or performs periodic data archiving.
  • Integration with external systems: If you need to integrate Dynamics 365 with external systems or services, the SysOperation framework can be utilized to handle the integration tasks as batch processes. This can include tasks such as synchronizing data between systems, processing messages from a message queue, or calling external web services.
  • Mass data updates: When you need to update a large number of records in Dynamics 365, the SysOperation framework can help you perform the updates efficiently. You can create a batch job that iterates through the records, applies the necessary updates, and commits the changes in batches, minimizing the impact on system performance.


Asynchronous VS Synchronous

The differences between asynchronous and synchronous processing in the SysOperation framework, it refers to how the processing is executed and how control is returned to the user interface.

  • Synchronous Processing: In synchronous processing, the batch job runs in the same session and thread as the user interface. When the user initiates the process, the system waits for the process to complete before control is returned to the user. This means that the user interface is blocked until the process finishes executing. Synchronous processing is typically used for short-running processes where immediate feedback is required.
  • Asynchronous Processing: In asynchronous processing, the batch job runs on a separate session and thread from the user interface. When the user initiates the process, control is immediately returned to the user interface, allowing the user to continue with other tasks. The batch job runs independently in the background, and the user can check the status or results later. Asynchronous processing is typically used for long-running processes or processes that don't require immediate feedback.


The choice between synchronous and asynchronous processing depends on the specific requirements of the business process. Synchronous processing provides immediate feedback and is suitable for short-running processes, but it can potentially block the user interface. Asynchronous processing allows the user to continue working while the process is running, but it might not provide immediate feedback.



Summary

In summary, the SysOperation framework in Dynamics 365 provides a structured approach for creating and executing batch processes. You can choose between synchronous and asynchronous processing based on the requirements of the business process, considering factors such as the duration of the process and the need for immediate feedback.

These are just a few examples of how the SysOperation framework in D365 can be used. Its flexibility and scalability make it a valuable tool for implementing a wide range of batch processing scenarios in Dynamics 365.

To use the framework, we will need the following three classes:

  • Data contract: This is a class that contains the properties required by the process class.
  • Processing: This is the class that actually does the work.
  • Controller: This is a class that extends SysOperationServiceController, which controls both the UI and the instantiation of the processing class.


Very basic example

  • Contract Class :

The contract class defines the parameters that will be passed to the service class for processing. In this example, let's assume we want to update customer group.

[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;
    }
}

  • Service Class :

The service class contains the business logic for processing 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;
    }
}

  • Controller Class :

The controller class is responsible for initiating 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();
    }
}

  • Create action menu item and name it (SCPCustGroupChangeController).
  • Change the Object Type property to Class and the Object property to (SCPCustGroupChangeController).

please follow the following images to try it out !

No alt text provided for this image
Create extension from AccountsReceivable menu and add the action menu item created to PeriodicProcesses as shown.
No alt text provided for this image
open ( change customer group ) menu item to change customer (DE-001) group from (30) to (80) as shown.
No alt text provided for this image

let's check customer group before changing it as shown it is (30)

No alt text provided for this image

after opening the the menu item it will show us the contract parameters as shown , let's change the group to (80).
No alt text provided for this image

if we check again the customer we will see it has been changed.

Comments