80671AE Development II in Microsoft Dynamics AX 2012 R3 CU8 HOL
Short Description
Development AX R3 Cu 8...
Description
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 job’s 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 (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 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
View more...
Comments