0% found this document useful (0 votes)
304 views25 pages

80671AE Development II in Microsoft Dynamics AX 2012 R3 CU8 HOL

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 25

Learning Portal

80671AE: Development II in Microsoft


Dynamics_AX 2012 R3 CU8
Hands-On-Lab

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Table of Contents
80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8 .......................................... 1
Exercise 1 Print to the Screen ........................................................................................................................................2
Exercise 2 Debug the Job ...............................................................................................................................................3
Exercise 3 Create an XML Developer Document ...........................................................................................................4
Exercise 4 Create a Times Table Using a While Loop .....................................................................................................5
Exercise 5 Create a Times Table Using a Do...while Loop ..............................................................................................6
Exercise 6 Create a Times Table Using a for Statement ................................................................................................7
Exercise 7 Create a Yes No Box ......................................................................................................................................8
Exercise 8 Create an Infolog Tree ..................................................................................................................................9
Exercise 9 Create a Dialog Box .....................................................................................................................................10
Exercise 10 Use X++ Control Statements .....................................................................................................................11
Exercise 11 Create a New Class ...................................................................................................................................12
Exercise 12 Allow Access to Methods ..........................................................................................................................13
Exercise 13 Instantiating a Class ..................................................................................................................................14
Exercise 14 Use Method Parameters ...........................................................................................................................15
Exercise 15 Create a Run Method ...............................................................................................................................16
Exercise 16 Create a Calculator Class ..........................................................................................................................17
Exercise 17 Retrieving Data .........................................................................................................................................19
Exercise 18 Update ......................................................................................................................................................20
Exercise 19 Create a Query Using X++ .........................................................................................................................21
Exercise 20 Handle an Exception .................................................................................................................................22

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

80671AE: Development II in Microsoft


Dynamics AX 2012 R3 CU8
Objectives

Scenario

Estimated Time to
Complete This Lab
Computers used in this
Lab

After completing this lab, you will be better able to:

Use the X++ editor to write code and the various operators available in X++

Complie code and review errors with the Complier

Create breakpoints and step through executing code with the Debugger

Declare and use extended data types for variables

Control program flow using condidtional statements in X++

Repetitively call the same blocks of code by using Loop statements

Create and use classes, methods

Access the Database

Handle exception

As a member of the Microsoft Dynamics AX 2012 R3 CU8 project team for


Adventure Works Cycles you are asked to set up various items in Dynamics AX.
30 Minutes

AX2012R3
The password for the Administrator account on all computers in this lab is:
w0rd@p@$$

Page 1 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 1
Print to the Screen
Scenario
The client wants you to demonstrate how to print a message to the screen. Create a job that prints a message to
the screen.
Create a job that prints the message "Microsoft Dynamics AX is fantastic.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Press Ctrl + D inside the development workspace to open the AOT.


b. Right-click the Jobs node and select New Job.
c. Select the jobs name in the first row.

AX2012R3
1.

Print to the Screen

d. Rename the job.


e. Add the following code: info("Microsoft Dynamics AX is fantastic.");.
f.

Click the Compile button on the toolbar or press F7 to compile..

g. Press F5 or click the Go button on the toolbar to run the job.


h. Close the Infolog dialog.

Page 2 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 2
Debug the Job
Scenario
The client wants you to verify the code executes without errors. Debug the job that you created in the previous
lab.
Set a breakpoint in the code in the job from the previous practice. Run the code and step through it.
Tasks

Detailed Steps

Complete the following


tasks on:

a. In the AOT, click the Jobs node.


b. Double-click on the job that created in the Print to the Screen exercise.
c. Select the line of code: static void <your jobname>(Args _args).

AX2012R3
1.

Debug the Job

d. Click the Toggle breakpoint icon.


e. Save the code by pressing Ctrl+S.
f.

Press the F5 key to run the code.

g. Step through the code by using the icon on the toolbar or F11.

Page 3 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 3
Create an XML Developer Document
Scenario
You have been asked to create developer documentation for the Credit Limit modifications made in the standard
Microsoft Dynamics AX application.
Create an XML file by using the XML documentation generation, for the Credit Limit development project.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Press Ctrl+Shift+P inside the development workspace to open the development

project tree.
b. Find the Credit Limit project.

AX2012R3
1.

Create an XML
Developer
Document

c. Right-click the project, and select Add-Ins > Extract XML documentation.
d. Click the Folder icon under the Documentation check box.
e. Enter a file name.
f.

Click Save.

g. Clear the Reflection check box.


h. Click OK.
i.

Click Close to close the Infolog window. The .xml file will be created at the
specified path.

j.

Go to the path provided by you for the file created on your system.

k. Review the file created.

Page 4 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 4
Create a Times Table Using a While Loop
Scenario
Isaac has been asked to demonstrate the use of a while statement by printing out the multiplication table for 2.

Create a job that prints the multiplication table for 2 using a while statement

Have the list contain all even numbers up to 50

Use a 'counter' variable to increment every time

Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create a Times Table


Using a While Loop

d. Add the following code:

int counter = 1;
while (counter <= 25)
{
print counter * 2;
counter++;
}
pause;
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

g. A print window will appear with the output of each iteration with the message

The X++ execution paused. Do you wish to continue?.


h. Click on Yes/No to close the window.

Page 5 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 5
Create a Times Table Using a Do...while Loop
Scenario
Isaac has been asked to demonstrate the use of a do...while statement by printing out the multiplication table for
2.

Create a job that prints the multiplication table for 2 using a do...while statement

Have the list contain all even numbers up to 50

Use a 'counter' variable to increment every time

Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create a Times Table


Using a Do...while
Loop.

d. Add the following code.

int counter = 1;
do
{
print counter * 2;
counter++;
}
while(counter <= 25);
pause;
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

g. A print window will appear with the output of each iteration with the message

The X++ execution paused. Do you wish to continue?


h. Click on Yes/No to close the window.

Page 6 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 6
Create a Times Table Using a for Statement
Scenario
Isaac has been asked to demonstrate the use of a for statement by printing out the multiplication table for 2.

Create a job that prints the multiplication table for 2 using a for statement

Have the list contain all even numbers up to 50

Use a 'counter' variable to increment every time

Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create a Times Table


Using a for
Statement.

d. Add the following code.

int counter;
for(counter = 1; counter <= 25; counter++)
{
print counter * 2;
}
pause;
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

g. A print window will appear with the output of each iteration with the message

The X++ execution paused. Do you wish to continue?.


h. Click on Yes/No to close the window.

Page 7 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 7
Create a Yes No Box
Scenario
Isaac has been asked to create a job that will prompt the user to continue or cancel. The user should be asked
whether he or she wants to continue and be able to choose Yes or No.
Create a new job in the AOT that contains a box where the user can decide to continue or cancel.

The caption on the window is "Question"

The text should be "Do you want to continue?"

The default button is "Yes"

Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create a Yes No Box.

d. Add the following code:

DialogButton

dialogButton;

dialogButton = Box::yesNoCancel("Do you want to continue?", DialogButton::Yes,


"Question", "Bottom help text");
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

g. Click on Yes/No/Cancel to close the window.

Page 8 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 8
Create an Infolog Tree
Scenario
Isaac has been asked to create an Infolog Tree that has an Info message, a Warning message and an Error message.
Create a tree of Infolog messages using a job in Microsoft Dynamics AX. The tree should have a root node which
states: "This is the Infolog Tree lab." The tree should contain at least one of each type of message (Info, Warning
and Error).
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create an Infolog
Tree.

d. Add the following code.

setPrefix("This is the Infolog Tree lab");


info("Info message");
warning("Warning message");
error("Error message");
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

g. Close the Infolog dialog.

Page 9 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 9
Create a Dialog Box
Scenario
Isaac has been asked to create a dialog box that will prompt the user to enter a customer account number and a
sales order ID.
Create a dialog box that lets the user select a customer account number and a sales order ID. Once the user clicks
OK, show the values of each selection using the Infolog.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Create a Dialog Box.

d. Add the following code.

Dialog

dialog;

DialogGroup

dialogGroup;

DialogField

dialogFieldCustAccount;

DialogField

dialogFieldSalesId;

dialog = new Dialog("Simple Dialog");


dialogGroup = dialog.addGroup("Customer");
dialogFieldCustAccount = dialog.addField(extendedTypeStr(CustAccount));
dialogFieldSalesId = dialog.addField(extendedTypeStr(SalesId));
if(dialog.run())
{
info(dialogFieldCustAccount.value());
info(dialogFieldSalesId.value());
}
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

Page 10 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 10
Use X++ Control Statements
Scenario
Isaac has been asked to create a job that will ask the user if he or she wants to display his or her date of birth. If
the user chooses Yes, the system should print the user's name and date of birth. If the user chooses No, the
system should only print the user's name.
Create a dialog for the user that determines, based on input, what appears on a screen.

Create a new job in the AOT and declare and initialize a DialogButton object variable and a container data
type variable

The three elements of the container are your first name, last name, and birth date

The Dialog button should be a Yes No box with the text "Do you want to display your birth date?" with
Yes being the default button

If Yes is clicked - first name, last name, and birth date appear

If No is clicked - only first and last name appear

Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Rename the job.

AX2012R3
1.

Use X++ Control


Statements

d. Add the following code:

DialogButton dialogButton;
container

nameAndDOB;

nameAndDOB = ["John","Doe",mkDate(28,9,71)];
dialogButton = Box::yesNo("Do you want to see the birthdate?",
DialogButton::Yes);
if (dialogButton == DialogButton::Yes)
{
Box::info(strFmt("%1 %2, %3", conPeek(nameAndDOB,1),
conPeek(nameAndDOB,2), date2str(conPeek(nameAndDOB,3),-1,-1,-1,-1,-1,-1)));
}
else
{
Box::info(strFmt("%1 %2",conPeek(nameAndDOB,1), conPeek(nameAndDOB,2)));
}
e. Press F7 or click the Compile button in the toolbar to compile the code.
f.

Press F5 or click the Go button in the toolbar to run the job.

Page 11 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 11
Create a New Class
Scenario
You have been asked to create a class that will print your name to the screen.
Create a new class that has one class variable that can hold your name. Create a method that will set the value of
the variable to be your name. Create another new method that can print the value of the variable.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Classes node, and then select New Class.
c. Rename the class to PrintMyName.

AX2012R3
1.

Create a New Class.

d. Expand the node for the newly created class.


e. Double-click classDeclaration(usr).

Declare a variable of type String, called "myName" as the below code:


class PrintMyName
f.

{
str 20

myName;

}
g. Press F8 to compile and save classDeclaration.
h. Right-click the PrintMyName(usr) class and select New > Method.
i.

Rename the method to "setMyName".

Enter the code in the setMyName method shown below into your method:
private void setMyName()
j.

{
myName = "Isaac";
}
k. Press F8 to compile and save the method.
l.

Right-click the PrintMyName(usr) class and select New > Method.

m. Rename the method to "printMyName".


n. Enter the code in the printMyName method show below into your method.

private void printMyName()


{
print MyName;
}
o. Press F8 to compile and save the method.

Page 12 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 12
Allow Access to Methods
Scenario
Allow the methods created in the previous lab to be called by code anywhere in the application.
The methods in the class created in the previous lab are marked private by default and so they cannot be accessed
by other application elements. You have been asked to allow the method to be accessed by other application
elements
Change the modifier of each method to Public.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Find the PrintMyName(usr) class created in the previous lab.
c. Double-click each method in the class.

AX2012R3
1.

Allow Access to
Methods

d. Change the method modifier from private to Public.


e. Save the changes.

Page 13 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 13
Instantiating a Class
Scenario
You have been asked to execute the code written in the previous lab.
Create a job that instantiates the class written in the previous lab, and executes the two methods you created.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node, and then select New Job.
c. Type the following code into the job:

AX2012R3
1.

Instantiating a Class.

PrintMyName

PrintMyName;

PrintMyName = new PrintMyName();


PrintMyName.setMyName();
PrintMyName.printMyName();
pause;
d. Press F7 or click the Compile button in the toolbar to compile the code .
e. Press F5 to compile and run the job.

Page 14 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 14
Use Method Parameters
Scenario
Isaac has been asked to write a method that accepts a parameter.
Modify your class to print your name, by allowing the method that sets the name variable to accept a parameter
and set the name variable from that parameter. You will also need to modify the job so that you pass your name
into the method when you run it.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Expand Classes.
c. Find the PrintMyName(usr) class created earlier in this lesson that prints your

name.

AX2012R3
1.

Use Method
Parameters.

d. Double-click the method setMyName(usr).


e. Modify the code so the method looks the same as shown in the following

example:
public void setMyName(str _myName)
{
myName = _myName;
}
f.

Press F8 to save and compile the code.

g. In the AOT, expand Jobs.


h. Find the Job1(usr) job that is created in the Instantiating a Class exercise to

execute the class.


Modify the job so that the line that calls the setMyName() method is called
with your name.
static public void executePrintMyName(Args _args)
i.

{
PrintMyName

PrintMyName;

PrintMyName = new PrintMyName();


PrintMyName.setMyName("Isaac");
PrintMyName.printMyName();
pause;
}
j.

Press F5 to save and run the job.

Page 15 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 15
Create a Run Method
Scenario
Isaac is required to create a method that calls other methods in the same class.
Add a method named run to the class that prints your name. From this method call the two methods that set and
print the value. Modify the job that executes the class to call the new run method.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Expand Classes.
c. Find the PrintMyName(usr) class created earlier in this lesson that prints your

name.

AX2012R3
1.

Create a Run
Method.

d. Right-click the class and select New > Method.


e. Modify the code so the method looks the same as shown in the following

example.
public void run()
{
this.setMyName("Isaac");
this.printMyName();
}
f.

Press F8 to save and compile the code.

g. Expand Jobs in the AOT.


h. Find the executePrintMyName(usr) job in the AOT that executes the class.

Modify the job to the code shown in the following example.


static void executePrintMyName(Args _args)
i.

{
PrintMyName

PrintMyName;

PrintMyName = new PrintMyName();


PrintMyName.run();
pause;
}
j.

Press F5 to save and run the job.

Page 16 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 16
Create a Calculator Class
Scenario
You have been asked to create a class than can do simple calculations on two numbers.
Create a class that has two class variables that are set using accessor methods. These variables are to hold 2
numbers. Add four methods that will add, subtract multiply and divide these 2 numbers, and then return the
calculated value. Write a job to test your class.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Classes node and select New Class.
c. Rename the class to Calculator.

AX2012R3
1.

Create a Calculator
Class.

d. Expand the node for the newly created class.


e. Double-click the classDeclaration(usr).

Modify the class to the code shown in the following example:


public class Calculator
f.

{
real value1;
real value2;
}
g. Press the F8 key to save and complie the code.
h. In AOT, right-click the Calculator(usr) class, and then click New > Method.

Modify the method to the code shown in the following example:


public real parmValue1(real _value1 = value1)
i.

{
value1 = _value1;
return value1;
}
j.

Click New to create new method.

k. Modify the method to the code shown in the following example:

public real parmValue2(real _value2 = value2)


{
value2 = _value2;
return value2;
}
l.

Click New to create new method.

Page 17 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Tasks

Detailed Steps
m. Modify the method to the code shown in the following example:

public real add()


{
return value1 + value2;
}
n. Click New to create new method.
o. Modify the method to the code shown in the following example:

public real subtract()


{
return value1 - value2;
}
p. Click New to create new method.
q. Modify the method to the code shown in the following example:

public real multiple()


{
return value1 * value2;
}
r. Click New to create new method.
s. Modify the method to the code shown in the following example:

public real divide()


{
return value1 / value2;
}
t. Press F8 to save and compile the code.
u. Open the AOT.
v. Right-click the Jobs node and select New Job.
w. Rename the job to Calculator and add below code to the code shown in the

following example:
static void calculator(Args _args)
{
Calculator calc = new Calculator();
calc.parmValue1(10.00);
calc.parmValue2(2.00);
info(strFmt(" Add = %1",calc.add()));
info(strFmt(" Sub = %1",calc.subtract()));
info(strFmt(" Mul = %1",calc.multiple()));
info(strFmt(" Devide = %1",calc.divide()));
}
x. Press F5 to save and run the job.
y. Close the Infolog form.

Page 18 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 17
Retrieving Data
Scenario
Isaac has been asked to produce a list of customer account numbers and names sorted by name.
Create a job that will retrieve all customer accounts and print the account number and name. The list should be
sorted by name. Note that the customer name is not stored in the customer table; it is stored in the DirPartyTable,
which is related to the customer table through the CustTable.Party field and the DirPartyTable.RecId field.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Add the following code:

AX2012R3
1.

Retrieving Data.

CustTable

custTable;

DirPartyTable

dirPartyTable;

while select dirPartyTable order by Name


join custTable
where custTable.Party == dirPartyTable.RecId
{
info(dirPartyTable.Name+', '+ custTable.AccountNum);
}
d. Press F5 to save and run the job.

Page 19 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 18
Update
Scenario
The item table needs to be updated so that all items in the item group TV&Video have a purchase tolerance of 2
percent. Isaac has been asked to write a job that will achieve this.
Write a job that will find all items in the Television item group, and set the price tolerance group to 2 percent.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Add the following code:

AX2012R3
1.

Update.

InventTable

inventTable;

InventItemGroupItem inventItemGroupItem;
ttsbegin;
while select forupdate inventTable
exists join inventItemGroupItem
where inventItemGroupItem.ItemId == inventTable.ItemId
&& inventItemGroupItem.ItemGroupId == 'TV&Video'
{
inventTable.ItemPriceToleranceGroupId ="2%";
inventTable.update();
}
ttscommit;
d. Press F5 to save and run the job.

Page 20 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 19
Create a Query Using X++
Scenario
Isaac has been asked to provide a list of vendors of packaging materials.
Write a job that will produce a list of vendors. The job should build a query using X++, and the query should have a
range that limits the list to vendors in vendor group "10", and sort by account number.
Add code that will allow the user to modify the query ranges at run time.
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Right-click the Jobs node and select New Job.
c. Add the following code.

AX2012R3
1.

Create a Query
Using X++.

Query

query;

QueryRun

queryRun;

QueryBuildDataSource

qbds;

QueryBuildRange

qbr;

VendTable

vendTable;

query = new Query();


qbds = query.addDataSource(TableNum(VendTable));
qbr = qbds.addRange(FieldNum(VendTable,VendGroup));
qbr.value('10');
qbds.addSortField(FieldNum(VendTable,AccountNum));
queryRun = new QueryRun(query);
if (queryRun.prompt())
{
while (queryRun.next())
{
vendTable = queryRun.get(tableNum(VendTable));
info(vendTable.Name());
}
}
d. Press F5 to save and run the code.

Page 21 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Exercise 20
Handle an Exception
Scenario
In this practice, you will use the exception handling features that are available in X++.
The Accounts Receivable Department has asked for a basic form that will create a new customer. They have
requested that the user is prompted for the account number, name and all mandatory fields. If the user does not
enter all the required data, the system must report which fields are missing, show a message that states "Please
enter all required fields," and not commit any data to the database. If any error occurs the system will display a
message that states "An error occurred. Please try again."
Create a new class that will prompt the user for a new customer account number, the name and all fields that are
mandatory for the customer records. Use existing methods to validate the record before inserting the record into
the database. In the case that not all data was entered, throw an error exception that has the error message:
"Please enter all required fields." The code to create the record must be inside a try/catch statement. This must
include a catch for the error exception type and display the message: "An error occurred. Please try again.".
Tasks

Detailed Steps

Complete the following


tasks on:

a. Open the AOT.


b. Find the Classes node.
c. Right-click and select New Class.

AX2012R3
1.

Handle an
Exception.

d. Expand the Class1(usr) node for the newly created class.


e. Double-click the classDeclaration(usr).

Rename the class to CustCreateCustomer as the below example:


class CustCreateCustomer
f.

{
}
g. Press F8 to save and complie classDeclaration.
h. Right-click the CustCreateCustomer(usr) class in the AOT.
i.

Click New > Method.

Modify the method to the code shown in the following example:


void run()
j.

{
Dialog

dlg = new Dialog("Create new customer");

DialogField

dlgCust;

DialogField

dlgGrp;

DialogField

dlgCur;

CustTable

custTable;

dlgCust = dlg.addField(extendedTypeStr(CustVendAc), "Customer account");


dlgGrp = dlg.addField(extendedTypeStr(CustGroupId));
dlgCur = dlg.addField(extendedTypeStr(CurrencyCode));

Page 22 of 23

80671AE: Development II in Microsoft Dynamics AX 2012 R3 CU8

Tasks

Detailed Steps
if (dlg.run())
{
try
{
custTable.AccountNum = dlgCust.value();
custTable.CustGroup
custTable.Currency

= dlgGrp.value();
= dlgCur.value();

if (!custTable.validateWrite())
{
throw error("Please enter all required fields.");
}
else
{
custTable.insert();
}
}
catch (Exception::Error)
{
error("An error occurred. Please try again");
}
}
}
k. Click New to create another method.

Modify the method to the code shown in the following example:


static void main(Args _args)
l.

{
CustCreateCustomer

custCreateCustomer = new

CustCreateCustomer();

custCreateCustomer.run();
}
m. Press F8 to save and complie the method.
n. Right-click the CustCreateCustomer(usr) class in AOT, and then click Open.

Page 23 of 23

You might also like