• No results found

Enter a From date and a To date and click OK

In document AX2012_ENUS_DEV_3 (Page 122-133)

Args Object

Lab 3.5 - Using Args

11. Enter a From date and a To date and click OK

12. The infolog will display the average sales price for that item. Click OK to close the infolog.

private itemId parmItemId(itemId _itemId = itemId) {

itemId = _itemId;

return itemId;

}

static void main(Args _args) {

if (_args.dataset() == tableNum(InventTable)) {

InventTable = _args.record();

SalesCalcAverageSalesPrice.parmItemId(InventTable.ItemId);

}

if (SalesCalcAverageSalesPrice.prompt()) SalesCalcAverageSalesPrice.run();

}

protected Object dialog() {

Dialog dlg = super();

dlgFromDate = dlg.addField(identifierStr(FromDate));

dlgToDate = dlg.addField(identifierStr(ToDate));

if (!itemId)

dlgItemId = dlg.addField(identifierStr(itemId));

return dlg;

}

public boolean getFromDialog() {

boolean ret;

fromDate = dlgFromDate.value();

toDate = dlgToDate.value();

if (!itemId)

itemId = dlgItemId.value();

ret = super();

return ret;

}

Summary

Using system classes in conjunction with your modifications will help leverage existing frameworks, and access important system data, to ultimately provide a richer and more consistent Microsoft Dynamics AX enhancement for end users.

Test Your Knowledge

Test your knowledge with the following questions.

1. Which of the following are Collection classes? (Select all that apply) ( ) Struct

( ) Map ( ) Container ( ) List

2. What class is used to iterate through the elements stored in a Map object?

3. RecordSortedList and RecordInsertList have some similarities but have different uses. Which of the following is a major difference between the two classes?

( ) RecordInsertList lacks the sort order features that are available in RecordSortedList.

( ) RecordSortedList lacks the sort order features that are available in RecordInsertList.

( ) RecordInsertList cannot insert multiple records into the database in one trip.

( ) RecordSortedList cannot insert multiple records into the database in one trip.

4. Match the following Application Object classes to their description:

_____ 1. Form

a. This class contains property methods for the properties on a form data source. Use this class to manipulate the properties on a form data source by using X++ code.

b. This is not a real class.

c. This class contains property methods for a form tree control.

d. This is not a real class.

_____ 6.

FormBuildTreeControl _____ 7.

FormQueryDataSource _____ 8. FormExecute

e. This class contains property methods for the properties on the Design node for a form and methods for creating controls.

f. This class contains methods for executing a form.

g. This class contains property methods for a form string control.

h. This class contains property methods for the form name and other form properties and methods that enable addition of data sources and controls to the form.

5. What does the ClassFactory.formRunClass() method do?

6. In which situations are the pack/unpack methods used in the RunBase framework.

7. Which method on Args should only be used when no other methods will suffice?

( ) parm() ( ) parmEnum()

Quick Interaction: Lessons Learned

Take a moment and write down three key points you have learned from this chapter

1.

2.

3.

Solutions

Test Your Knowledge

1. Which of the following are Collection classes? (Select all that apply) (√) Struct

(√) Map ( ) Container (√) List

2. What class is used to iterate through the elements stored in a Map object?

MODEL ANSWER:

MapEnumerator.

MapIterator is also correct, but a secondary choice.

3. RecordSortedList and RecordInsertList have some similarities but have different uses. Which of the following is a major difference between the two classes?

(•) RecordInsertList lacks the sort order features that are available in RecordSortedList.

( ) RecordSortedList lacks the sort order features that are available in RecordInsertList.

( ) RecordInsertList cannot insert multiple records into the database in one trip.

( ) RecordSortedList cannot insert multiple records into the database in one trip.

4. Match the following Application Object classes to their description:

a. This class contains property methods for the properties on a form data source. Use this class to manipulate the properties on a form data source by using X++ code.

b. This is not a real class.

c. This class contains property methods for a form tree control.

d. This is not a real class.

e. This class contains property methods for the properties on the Design node for a form and methods for creating controls.

f. This class contains methods for executing a form.

g. This class contains property methods for a form string control.

h. This class contains property methods for the form name and other form properties and methods that enable addition of data sources and controls to the form.

5. What does the ClassFactory.formRunClass() method do?

MODEL ANSWER:

Given a reference to a form in the AOT, this method will return a FormRun object, which is a runnable form object.

6. In which situations are the pack/unpack methods used in the RunBase framework.

MODEL ANSWER:

To save and restore user input and to transfer the object from the client to the server.

7. Which method on Args should only be used when no other methods will suffice?

(•) parm() ( ) parmEnum() ( ) parmEnumType() ( ) record()

CHAPTER 4: FORMS

Objectives

The objectives are:

• Identify the main sections that make up a form.

• Add data sources to a form to define what data is displayed by the form.

• Add controls to a form to display data.

• Modify form methods to the control how the form behaves when it opens and closes.

• Make decisions about where to place the code.

• Make runtime modification of the fetch of data.

Introduction

This lesson provides a comprehensive foundation for using forms to interact with the end-user.

The following topics will be discussed:

• Forms architecture

• Fetch of data

• Code placement in forms

• Advanced controls

• Special forms

Scenario

Isaac, the systems developer, is required to create a new form that has multiple data sources linked together, fields that are calculated from other fields, fields that are not linked to a data source, and to initialize the fields on the form when the form opens. He has also been asked to investigate other types of forms and form controls.

Architecture

A form supports the interaction between the user and the database. It focuses on the following actions.

• Displaying and receiving data

• Filtering data

• Sorting data

• Modifying data

The application and business logic are not integrated in forms but programmed on the underlying tables and classes.

The following figure illustrates the structure of a form as displayed in the AOT.

FIGURE 4.1 THE SECTIONS OF A FORM A form consists of five components in the AOT:

• Methods

• Data sources

• Parts

• Designs

• Permissions

All of these components have been described in previous Microsoft Dynamics AX 2012 development courses. This course goes in to more detail about the three main sections - Methods, Data sources and Design.

Methods

System generated methods, also known as system methods, standard methods or object methods, attached to the form are used to control the startup and shut down of the form. These events are frequently overridden to make initialization of the form. By default, the system methods are not displayed. To override a system method, right-click on the Methods node, select Override Method and then select the methods to override.

Other methods can be added and called from anywhere in the form. It is good practice to add methods here rather than writing large chunks of code in the objects deeper in the form design, as it makes locating code simpler.

Variables defined in the class declaration of the individual form can be accessed from all methods in the form and can be used to hold the status of the form controls.

The following illustration shows the CustTable form methods. The form system methods task, run, init and close have been overridden. All other methods have been added to the Methods node and are specific to this form.

FIGURE 4.2 CUSTTABLE FORM METHODS

In document AX2012_ENUS_DEV_3 (Page 122-133)