Wednesday, November 7, 2018

Edit and Display Method in AX

Using the edit Method Modifier

The edit method modifier is used to indicate that a method’s return value is to be displayed on a form, and users can edit that value. If you don't want users to edit the value, use a display method.
Use the edit method modifier on the following:
  • Table methods
  • Form methods
  • Form data source methods
Write your edit methods on a table. You can use the same code in several forms.
edit methods are called each time the form is redrawn. They should not contain complex and time-consuming calculations.

Create an edit Method

Create an edit method on a form or table.
  1. Place the edit keyword immediately in front of the method’s return type.
  2. Create a Boolean parameter called Set. It is used to determine whether the user has entered anything into the control.
  3. Create a second parameter to hold the values that the user has entered into the control.
  4. If the edit method is on a form data source, create a third parameter for the data source. Place this parameter after the Set parameter.
Following is an example of an edit method on a table.
edit FreeTxt txtDefault(boolean Set, FreeTxt Txt)
Following is an example of an edit method on a form data source.
edit Amount settle(boolean set, CustTrans _CustTrans, Amount U)
edit methods must have a return type. The return value is typically a calculated value (for example, a sum). 

Use an edit Method on a Form or a Report

To use an edit method on a form, the control and the return type of the method must have identical types. For example, if you have a RealEdit control on your form, the edit method you are using must return a value of type real.
Add the edit method to a form control.
  1. Set the DataSource property for the control to the data source that contains the method.
    If you do not set the DataSource property, the system assumes that the method has been defined on the form.
  2. Set the DataMethod property to the name of the method.
You might also want to set the ExtendedDataType or ArrayIndex properties:
  • If the ExtendedDataType property is set, formatting, Help text, and so on are inherited from the type specified here.
  • If the edit method returns an array, set ArrayIndex to 0 to indicate that all array elements are to be shown in the control. If, for example, you set it to 2, only array element number two is shown.

Using the display Method Modifier


The display method modifier indicates that the method has a return value that can appear on a form or a report. A display method is any method that includes the display keyword as a method modifier. You can use the display method modifier with the following kinds of methods:
  • Table methods
  • Form methods
  • Form data source methods
  • Report methods
  • Report design methods
You should add a display method as a table method whenever possible. This enables you to use that same code with more than one form or report.

When you create or use a display method, you should be aware of the following issues:
  • The display method is called every time that the form is redrawn. To optimize form performance, the display method should not contain complex and time-consuming calculations.
  • The use of a display method can cause unintended information to become visible. For more information, see Security on Display and Edit Methods.
  • A display method is not activated if the method appears on a hidden tabbed page.
  • You have to add the display keyword to a form data source method when the return value of that method appears on a grid control.
  • To improve the performance of a display method, you can cache the method. For more information, see Caching display Methods.

To create a display method

To create a display method, follow these steps.
  1. Place the display keyword immediately in front of the method’s return type. For example:
    display Amount amount()
  2. Specify the return type. The return type should be an extended data type. In the previous step, the method has a return type of Amount.
    Typically, a display method returns a calculated value like a sum or count. For an example of a calculated value, see How to: Add a Control to a Form.
  3. Determine whether to add parameters to the display method. The following list shows when to add a parameter.
    • A display method for a table, form, report, or report design does not have any parameters. For example:
      display Amount amount()
    • A display method for a form data source does require a parameter. You use the parameter to specify a table buffer. The type of the table buffer has to match the type of the table in the form data source.
      The following example shows a display method that returns the number of customer records that appear in the form. Notice how the parameter has a type of CustTable. This table is in the form data source.
      X++
          display NumberOfRecords testMethod(CustTable myTable)
          {
             NumberOfRecords recCount = this.totalNumberOfRows();
             Return recCount;
          }
      

To use a display method in a form

To use a display method with a form control, the control and the return type of the method must be identical types. For example, if you have a RealEdit control on the form, the display method that you are using must return a value of type real.
The following steps show how to use a display method with a form control.
  1. Set the DataSource property for the control to the data source that contains the method.
    If you do not set the DataSource property, the system assumes that the display method is defined as a form method.
  2. Set the DataMethod property to the name of the display method.
  3. For some types of controls, you might also want to set the following properties:
    Property
    Description
    ExtendedDataType
    If this property is set, formatting, Help text, and other property values are inherited from the specified type.
    ArrayIndex
    If the display method returns an array, set this property to 0. The value 0 indicates that all array elements are to be shown in the control. If, for example, you set it to 2, only array element number two is shown.

To use a display method in a report

You can use display methods to provide data for reports. For a SQL Server Reporting Services report, you use a query as the data source for the report. You can use the display methods from the tables in that query to provide the data that appears in the report. For more information, see How to: Use Display Methods in a Report.
You can also use display methods with reports that you create or update with the X++ reporting framework. For example, the following steps use a display method from a table to specify a value for a control in a report.
  1. Set the Table property for the control to the table that contains the display method that you want to use.
    If you do not set the Table property, the system assumes the specified display method is defined as a report or report design method.
  2. Set the DataMethod property to the name of the display method.

No comments:

Post a Comment

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// &l...