80671AE Development II in Microsoft Dynamics AX 2012 R3 CU8 HOL
80671AE Development II in Microsoft Dynamics AX 2012 R3 CU8 HOL
80671AE Development II in Microsoft Dynamics AX 2012 R3 CU8 HOL
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
Scenario
Estimated Time to
Complete This Lab
Computers used in this
Lab
Use the X++ editor to write code and the various operators available in X++
Create breakpoints and step through executing code with the Debugger
Handle exception
AX2012R3
The password for the Administrator account on all computers in this lab is:
w0rd@p@$$
Page 1 of 23
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
AX2012R3
1.
Page 2 of 23
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
AX2012R3
1.
g. Step through the code by using the icon on the toolbar or F11.
Page 3 of 23
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
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.
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.
Page 4 of 23
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
Tasks
Detailed Steps
AX2012R3
1.
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.
g. A print window will appear with the output of each iteration with the message
Page 5 of 23
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
Tasks
Detailed Steps
AX2012R3
1.
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.
g. A print window will appear with the output of each iteration with the message
Page 6 of 23
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
Tasks
Detailed Steps
AX2012R3
1.
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.
g. A print window will appear with the output of each iteration with the message
Page 7 of 23
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.
Tasks
Detailed Steps
AX2012R3
1.
DialogButton
dialogButton;
Page 8 of 23
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
AX2012R3
1.
Create an Infolog
Tree.
Page 9 of 23
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
AX2012R3
1.
Dialog
dialog;
DialogGroup
dialogGroup;
DialogField
dialogFieldCustAccount;
DialogField
dialogFieldSalesId;
Page 10 of 23
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
Tasks
Detailed Steps
AX2012R3
1.
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.
Page 11 of 23
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
AX2012R3
1.
{
str 20
myName;
}
g. Press F8 to compile and save classDeclaration.
h. Right-click the PrintMyName(usr) class and select New > Method.
i.
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.
Page 12 of 23
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
AX2012R3
1.
Allow Access to
Methods
Page 13 of 23
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
AX2012R3
1.
Instantiating a Class.
PrintMyName
PrintMyName;
Page 14 of 23
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
name.
AX2012R3
1.
Use Method
Parameters.
example:
public void setMyName(str _myName)
{
myName = _myName;
}
f.
{
PrintMyName
PrintMyName;
Page 15 of 23
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
name.
AX2012R3
1.
Create a Run
Method.
example.
public void run()
{
this.setMyName("Isaac");
this.printMyName();
}
f.
{
PrintMyName
PrintMyName;
Page 16 of 23
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
AX2012R3
1.
Create a Calculator
Class.
{
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.
{
value1 = _value1;
return value1;
}
j.
Page 17 of 23
Tasks
Detailed Steps
m. Modify the method to the code shown in the following example:
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
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
AX2012R3
1.
Retrieving Data.
CustTable
custTable;
DirPartyTable
dirPartyTable;
Page 19 of 23
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
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
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
AX2012R3
1.
Create a Query
Using X++.
Query
query;
QueryRun
queryRun;
QueryBuildDataSource
qbds;
QueryBuildRange
qbr;
VendTable
vendTable;
Page 21 of 23
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
AX2012R3
1.
Handle an
Exception.
{
}
g. Press F8 to save and complie classDeclaration.
h. Right-click the CustCreateCustomer(usr) class in the AOT.
i.
{
Dialog
DialogField
dlgCust;
DialogField
dlgGrp;
DialogField
dlgCur;
CustTable
custTable;
Page 22 of 23
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.
{
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