To Override a Virtual Method

In a graph extension, you can override the virtual methods defined within the base graph. As with the event handlers, you have two options:
  • You can define the override method with exactly the same signature—that is, the return value, the name of the method, and all method parameters—as the overridden base virtual method has. As a result, the method is added to the queue of all override methods. When the system invokes the base method, all methods in the queue are executed sequentially, from the first one to the last one. The lower the level of the graph extension, the earlier the system invokes the override method.
  • You can define the override method with an additional parameter, which represents the delegate for one of the following:
    • The override method with an additional parameter from the extension of the previous level, if such a method exists
    • The base virtual method, if no override methods with additional parameters declared within lower-level extensions exist
In both cases, you should attach the PXOverride attribute to the override method declared within the BLC extension, as described in the following sections below:

Override Method That Is Added to the Override Method Queue

By declaring an override method with exactly the same signature as the overridden base virtual method has, you extend the base method execution. The base BLC method is replaced at run time with the queue of methods, which starts with the base BLC method. When the system invokes the base method, all methods in the queue are executed sequentially, from the first one to the last one. The lower the level the BLC extension has, the earlier the system invokes the override method. If the system has invoked the base method, you have no option to prevent the override method queue from execution. To prevent the base method executions, see the Override Method That Replaces the Original Method section below.

To add an override method that is added to the override method queue, perform the following actions:
  1. Create the graph extension, as described in To Start the Customization of a Graph.
  2. In the Code Editor, click View Source to view the code of the base graph in the Source Code browser.
    Note: In an instance of MYOB Acumatica, a repository with the original C# source code of the application is kept in the \App_Data\CodeRepository folder of the website.
  3. In the browser, select and copy the code of the method.
  4. In the Code Editor, paste the method code in the graph extension.
  5. In the graph extension, insert the PXOverride attribute immediately before the method signature.
  6. Clear the method body.
  7. Develop the code of the method.
  8. Click Save in Code Editor to save your changes.

Override Method That Replaces the Original Method

The override method with an additional parameter replaces the base BLC virtual method. When the virtual method is invoked, the system invokes the override method with an additional parameter of the highest-level BLC extension. The system passes a link to the override method with an additional parameter from the extension of the previous level, if such a method exists, or to the base virtual method.

You use a delegate as an additional parameter to encapsulate the method with exactly the same signature as the base virtual method. If the base virtual method contains a list of parameters, then you should not use the same list of parameters when you declare the override method with an additional parameter. To declare a MyMethod override method with an additional parameter within a BLC extension, you can use the following example.

public class BaseBLCExt : PXGraphExtension<BaseBLC>
{
  public delegate ReturnType MyMethodDelegate([List of Parameters]); 
  [PXOverride]
  public ReturnType MyMethod([List of Parameters,] MyMethodDelegate baseMethod)
  {
    return baseMethod(adapter);
  }
}

You can decide whether to call the method pointed to by the delegate. By invoking the base method, you also start the execution of the override method queue.

To add an override method that replaces the base BLC virtual method, perform the following actions:
  1. Create the graph extension, as described in To Start the Customization of a Graph.
  2. In the Code Editor, click Override Method, as shown in the screenshot below.
  3. In the Selected column of the Select Methods to Override dialog box, which opens, select the method to be overridden.
  4. Click Save to add the code template for the override method to the graph extension.
    Figure 1. Selecting a method to be overridden


Once the override method template has been created (see the following screenshot), you can implement the needed code within the template.
Figure 2. Viewing the override method template in the Code Editor


When you publish the customization project, the platform saves the graph extension as a C# source code file in the App_RuntimeCode folder of the website. You can later develop the event handler in Microsoft Visual Studio. (See Integrating the Project Editor with Microsoft Visual Studio for details.)