Standard Form methods in D365 F&O - X++ Code

Rumman Ansari   Software Engineer   2023-05-18   3802 Share
☰ Table of Contents

Table of Content:


Forms are main elements of finance and operations development. Many standard forms are already available in the application.

You can also create new forms. Each form consists of form methods, which can be classified as standard methods or custom methods. Standard methods must have a super() call to implement the parent method. Standard and custom methods are available with all standard and custom forms. You can extend the existing form methods and include code by using chain of command.

Form methods in D365 F&0 - X++ Code

The following sections explain the standard form methods in the finance and operations apps development platform.

init()

The init() method is a standard method that's called when a form is opened. This method helps to initialize the form, and it's run after the constructor method new(). The init() method is responsible for creating the runtime interface of the form. Mostly, you'll use this method when you need to:

  • Initialize the form level variables.
  • Get parameter data from args().
  • Initialize a data source query.
  • Set the properties of the controls that aren't record dependent.

Example

You have a custom form with a table named TrainingMaster. The table has an enum type field called TrainingType that has two values: Online and Classroom. The form should be opened with those records where TrainingType is Online.

The code pattern is as follows:


public void init()
{
        super();
        TrainingMaster_ds.query().dataSourceName("TrainingMaster")
        .addRange(fieldNum(TrainingMaster,TrainingType))
        .value(enum2Str(TrainingType::Online));
}

Modifications to the data source should be done only after the super() call because the base initialization happens there.

close()

The close() method is a standard method that's called when a form is closed. The super() call in this method closes the form, manages the database updates, and sets the closed() method to true. You can use the closeCancel() or closeOK() methods to initiate the close() method. Additionally, you can use the close() method to forcefully clear the values of some variable or to deallocate a class. Make sure that you complete these actions before the super() call. Often, NumberSequence classes are called from the close() method to facilitate an abort operation.

closeCancel()

The closeCancel() method is a standard method that's called when a form is canceled. The super() call in this method updates the Boolean value of closedCancel()and ensures that the modifications in the form aren't saved.

closeOK()

The closeOK() method is a standard method that's called when a form is closed by selecting the OK button. The super() call in this method updates the Boolean value of closedOK() and calls the close() method.

run()

The run() method is a standard method that's called immediately after the init() method. The super() call in this method makes the form window appear on the screen and performs a database search for the data to be displayed in the form.

Typical reasons for overriding this method include:

  • Activating or deactivating some fields.
  • Modifying the query.

Read More about:

  1. Standard Sorm data source methods in D365 F&0 - X++ Code
  2. Extension of a form method - Chain of command - D365 F&O - X++ Code
  3. Extension of a form data source method - Chain of command- D365 F&O - X++ Code
  4. Extension of a form data source field method - Chain of command- D365 F&O - X++ Code
  5. Extension of a form control method - Chain of command- D365 F&O - X++ Code