ax2012 enus wn dev 03

18
Chapter 3: Development with Visual Studio CHAPTER 3: DEVELOPMENT WITH VISUAL STUDIO Objectives The objectives are: Provide an overview of the improvements made to the Visual Studio Tools for Microsoft Dynamics ® AX 2012. Learn how to write business logic in managed code and integrate with Microsoft Dynamics AX 2012. Introduction The Visual Studio Tools for Microsoft Dynamics AX 2012 provide a set of tools and functionalities that supports modeling business application elements in Visual Studio and business logic development in managed code. Some of these tools and functionalities are part of the MorphX development environment and some of them are part of the Visual Studio environment. Some main improvements include the following: Support development in managed code . Browse AX metadata from inside Visual Studio. Store Visual Studio projects in the AX model store/repository. Model SSRS reports and write managed reporting business logic. Develop Enterprise Portal web controls. Develop and debug managed code integrating with AX, using proxies and events. Debug server side batch and services X++ code. Source control is available on Visual Studio projects (and contained items) that were added to the Application Object Tree (AOT). 3-1 Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Upload: silvia-bedejova

Post on 18-Dec-2015

10 views

Category:

Documents


7 download

TRANSCRIPT

  • Chapter 3: Development with Visual Studio

    CHAPTER 3: DEVELOPMENT WITH VISUAL STUDIO Objectives

    The objectives are:

    Provide an overview of the improvements made to the Visual Studio Tools for Microsoft Dynamics AX 2012.

    Learn how to write business logic in managed code and integrate with Microsoft Dynamics AX 2012.

    Introduction The Visual Studio Tools for Microsoft Dynamics AX 2012 provide a set of tools and functionalities that supports modeling business application elements in Visual Studio and business logic development in managed code. Some of these tools and functionalities are part of the MorphX development environment and some of them are part of the Visual Studio environment. Some main improvements include the following:

    Support development in managed code . Browse AX metadata from inside Visual Studio. Store Visual Studio projects in the AX model store/repository. Model SSRS reports and write managed reporting business logic. Develop Enterprise Portal web controls. Develop and debug managed code integrating with AX, using

    proxies and events. Debug server side batch and services X++ code. Source control is available on Visual Studio projects (and contained

    items) that were added to the Application Object Tree (AOT).

    3-1

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Visual Studio Tools In Microsoft Dynamics AX 2012, the following three user interface components are combined to provide a Microsoft Dynamics AX development experience in Visual Studio.

    Microsoft Dynamics AX Application Explorer Microsoft Dynamics AX Modeling Project Microsoft Dynamics AX Model Editor

    These help developers display, edit and use Microsoft Dynamics AX metadata.

    FIGURE 3.1 VISUAL STUDIO TOOLS

    Microsoft Dynamics AX Model Project

    Microsoft Dynamics AX Model projects are used to enable the Microsoft Dynamics AX development experience in Visual Studio. Creating a project is the starting point of any work that is performed in Visual Studio. After adding the project to the AOT, all required Visual Studio features are enabled to use Microsoft Dynamics AX metadata. The Microsoft Dynamics AX Model projects serve as units of work, grouped by the developer, for easier access to the required application elements and they narrow the scope of displayed application elements.

    In Microsoft Dynamics AX 2012 the following improvements were made to the Microsoft Dynamics AX Model projects:

    Project information is no longer stored as .moxl files. Application metadata is stored in a SQL-based database. Application metadata is visible in the AOT as a modeling project.

    3-2

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Opening the project is achieved by double-clicking the project in the AOT.

    Visual Studio can be started explicitly with a client configuration (command line parameter), or without. If it is started without, the default configuration will be used.

    As soon as Visual Studio has a connection to an Application Object Server (AOS), the user can browse the metadata in the Application Explorer, including read-only view of X++ code.

    The projects can be ad hoc projects which are stored in the AOT. If a project is ad hoc, the reports and web controls are still saved in

    the AOT. If the user wants to save the project, or if the user needs to integrate

    with proxies/event handlers, the project must be added to the AOT Client definition is needed to connect to metadata such as layer,

    model, company, and AOS connection.

    Scenario: Create a Microsoft Dynamics AX Model Project

    Isaac, the Developer, wants to create a new Reporting Services report for Microsoft Dynamics AX. Creating this report involves creating several other model elements, such as Style Templates and Queries. These elements are used by the new Report definition. The Microsoft Dynamics AX application model contains a large and growing number of elements. Isaac wants to separate the useful context from the whole application context and needs to group relevant elements that are made up his solution.

    Procedure: Create a Microsoft Dynamics AX Model Project

    To create a Microsoft Dynamics AX Model project in Visual Studio 2010, follow these steps:

    1. Open Visual Studio. 2. Click File > New > Project. 3. Select Microsoft Dynamics AX. 4. Select Report Model. 5. Enter a project name into the Name field and then click OK. 6. Verify the model project is created and is visible in the Solution

    Explorer window.

    Microsoft Dynamics Application Explorer

    The Microsoft Dynamics Application Explorer displays a view of the AOT within Visual Studio. In the Application Explorer, you can view, edit, and delete elements in the AOT.

    3-3

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Procedure: Add Elements

    To add elements to a Microsoft Dynamics AX Model project in Visual Studio using the Application Explorer, follow these steps:

    1. Expand the SSRS reports node. 2. Right-click the Reports node and select New Report. 3. Verify the new report is created and is visible under the model node

    in the Solution Explorer. 4. Right-click the new report node and select Rename. 5. Name the report. 6. Within the Application Explorer find a report that you want to

    change. 7. Right-click and select Add to project. 8. Verify the report is added to the project and is visible under the

    model project in the Solution Explorer window.

    NOTE: If the Microsoft Dynamics AX Application Explorer is not visible, open the Microsoft Dynamics AX Application Explorer by clicking View > Application Explorer.

    Procedure: Remove Elements

    To remove elements from a Microsoft Dynamics AX Model project in Visual Studio, follow these steps:

    1. Open the AX Model project. 2. Select the report that you want to remove. 3. Right-click the report. 4. Select Exclude from project. 5. Click Yes. 6. Verify the report is removed from the project.

    Microsoft Dynamics AX Model Editor

    The Microsoft Dynamics AX modeling operations in Visual Studio are performed in the Microsoft Dynamics AX Model Editor. The Microsoft Dynamics AX Model Editor now displays one concept (top-level AOT element) for each window. Drag-and-drop operations can be made by using multiple Model Editor windows, by using the Application Explorer, or directly from the Model Project.

    3-4

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Procedure: Edit Elements

    To add elements to a model project in Visual Studio, follow these steps:

    1. Open the Application Explorer. 2. Find the model project and right-click the project node. 3. Click Edit. 4. Expand the report in the Model Editor. 5. Right-click the Datasets node and then click Add Dataset. 6. In the Properties window, specify the following values.

    a. Set the Data Source property to Dynamics AX. b. Set the Data Source Type property to Query. c. Set the Name. d. Set the Query.

    7. In the Model Editor, select the datasource node and drag it onto the

    Designs node. An auto design named AutoDesign1 is created for the report.

    8. Right-click AutoDesign1 and select Properties. 9. Make sure that the Properties window is visible. 10. Enter a report template into the LayoutTemplate field. 11. In the Model Editor, right-click the AutoDesign1 node, and then

    click Preview to view the new style settings for the report. 12. Close the Preview window. 13. Save the report.

    3-5

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Lab 3.1 - Visual Studio Tool This lab will demonstrate how to use the Visual Studio Tool to create a Microsoft Dynamics AX Model project, find objects in the AOT and group relevant elements that make up a solution.

    Scenario

    Isaac, the Developer, wants to create a new SSRS based report for Microsoft Dynamics AX to show customer data. He needs to create a Model project to group relevant elements that make up his solution in a Model project.

    Challenge Yourself!

    Use the information that is provided to add a new Microsoft Dynamics AX Model project in Visual Studio and add the objects that are needed to create a new Reporting Services based report.

    Need a Little Help?

    1. Open Visual Studio. 2. Create a Report Model. 3. Create a new report in the Application Explorer. 4. Add the new report to the ReportDemoModel1 project.

    Step by Step

    1. Open Visual Studio. 2. Click File > New > Project. 3. Select Microsoft Dynamics. 4. Select Report Model. 5. Enter ReportDemoModel1 into the Name field and then click OK. 6. Verify the ReportDemoModel1 project model is created and is

    visible in the Solution Explorer window. 7. Expand the SSRS reports node and right-click the Reports node. 8. Click New Report. 9. Verify the new report is created and is visible under the

    ReportModel1 node in the Solution Explorer. 10. Right-click the new report node and select Rename. 11. Name the report ReportDemo1. 12. In the Application Explorer, select the report ReportDemo1. 13. Right-click the report and select Edit. 14. Expand the report in the Model Editor. 15. Right-click the Datasets node and then click Add Dataset.

    3-6

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    16. In the Properties window, specify the following values. a. Set the Data Source property to "Dynamics AX." b. Set the Data Source Type property to "Query." c. Set the Name property to CustTable. d. Set the Query property to SELECT

    CustTable.1.AccountNum,CustTable.1.CustGroup FROM CustTable.

    17. In the Model Editor, select the datasource node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report.

    18. Right-click AutoDesign1 and select Properties. 19. Make sure that the Properties window is visible. 20. In the LayoutTemplate field select ReportLayoutStyleTemplate from

    the drop down. 21. In the Model Editor, right-click the AutoDesign1 node, and then

    click Preview to view the new style settings for the report. 22. Close the Preview window. 23. Save the report. 24. Right-click the project in Solution Explorer and select Add

    to AOT.

    3-7

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Managed Code In earlier releases of Microsoft Dynamics AX users can call out from X++ code to managed code. In Microsoft Dynamics AX 2012, the new Business Connector enables C# or other managed programs to use the functionality that is provided by the Microsoft Dynamics AX stack.

    Improvements in Microsoft Dynamics AX 2012 include the following:

    Managed code project, such as C# or Visual Basic class library projects can be saved in the AOT.

    Managed code projects can be customized using the various layers. Managed code projects are updated when Visual Studio solutions are

    built and can be automatically deployed if required. Any modifications to the managed project are immediately reflected in the AOT.

    Scenario: Adding a Managed Code Project

    Isaac, the Developer, is implementing a custom commission engine that is written in C# and he invokes that commission engine from strategically included X++ access points. Since the commission engine needs to read a large amount of Microsoft Dynamics AX data, it is more efficient to do the processing on the server side. From C#, Isaac wants to use the proxies instead of reading the data directly by using other technologies such as ADO.NET.

    Isaac wants to be able to include his managed project as a Microsoft Dynamics AX asset for it to be shipped and customized with the rest of the Microsoft Dynamics AX application.

    Procedure: Adding a Managed Code Project

    To add managed code to Microsoft Dynamics AX 2012, follow these steps:

    1. Open Visual Studio. 2. Select File > New > Project to create a new project of type Class

    Library. 3. Enter a name into the Name field and then click OK. 4. Create a C# Class. 5. Right-click the solution and select Build Solution. 6. Right-click the project and then click Add to AOT. 7. Open the AOT and verify the project is added to the AOT in

    Microsoft Dynamics AX 2012.

    3-8

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Proxies

    It is possible to add X++ classes and tables to a VS project to enable access from managed code. When adding an AOT element to a project by using the Application Explorer, a proxy for that class is created internally and features, such as IntelliSense, are made available.

    Scenario: Adding an AOT Object

    Isaac, the Developer, wants to be able to reuse some code already written in an X++ class and include the AOT object in his managed code project.

    Procedure: Adding an AOT Object

    To add an AOT object to the managed code project, follow these steps:

    1. Open Microsoft Dynamics AX. 2. Open the AOT. 3. Right-click the Classes node and create a new class. 4. In Visual Studio find the class created in Step 2 in the Application

    Explorer. 5. Add the class to the Model project that you created in the previous

    procedure. 6. Call the X++ class from the managed code.

    Deployment

    Managed code is deployed automatically to physical locations on the client and server to help the developer experiencing the same seamlessness as in X++ when developing for the Microsoft Dynamics AX application.

    Cross-Reference Tool

    The Cross-reference tool in Microsoft Dynamics AX is used to view the relationships between objects. It shows which other objects the current object uses or which other objects use the current object. The Cross-reference tool fully supports Visual Studio projects in the AOT under the Visual Studio Projects node.

    Scenario: Research AOT Objects

    Isaac, the Developer, has started to customize a class in Microsoft Dynamics AX. However, he does not know much about how the object interacts with other objects. He uses the Cross-reference tool to view the relationships between objects.

    3-9

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Procedure: Research AOT Objects

    To research object relations using the Cross-reference tool, follow these steps:

    1. In Microsoft Dynamics AX 2012 open the AOT. 2. Expand the Classes node and select a class that is used in managed

    code. 3. Right-click the class and select Add-Ins > Cross-reference > Used

    by.

    3-10

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Lab 3.2 - Managed Code This lab will demonstrate how to use existing X++ classes in a managed code assembly. It will also show how to add the managed code project as a Microsoft Dynamics AX asset so that it can be shipped and customized with the rest of the Microsoft Dynamics AX application.

    Scenario

    Isaac, the Developer, is implementing a custom commission engine written in C# and he invokes that commission engine from strategically included server-side X++ hook points. For security reasons, the engine is designed to run on the server. Because the process has to read large amounts of DAX data, it is more efficient to execute the business logic on the server side.

    Isaac wants to be able to include the commission engine assembly as a Microsoft Dynamics AX asset so that it can be shipped and customized with the rest of the Microsoft Dynamics AX application.

    One of the classes he needs to create will retrieve a customer name given the customer ID. The class to retrieve the name will be created in Microsoft Dynamics AX to demonstrate how X++ classes can be used in managed code.

    Challenge Yourself: Create X++ Object

    Use the information that is provided to create a manage code sample that uses existing X++ code to retrieve a customer name given the customer ID. Create the X++ object that is called from the managed code.

    Challenge Yourself: Managed Code

    The managed code project should be added as a Microsoft Dynamics AX asset so that it can be shipped and customized with the rest of the Microsoft Dynamics AX application.

    Challenge Yourself: Research Object Relations

    Use the cross-reference tool to analyze the object relation.

    Need a Little Help?

    1. Create new project of type Class Library in Visual Studio. 2. Create a C# method. 3. Add the project to Microsoft Dynamics AX. 4. Create a new class in Microsoft Dynamics AX. 5. In Visual Studio, use the Application Explorer to add the class to

    the C# project. 6. Call the X++ class from inside the managed code project.

    3-11

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Step by Step: Create X++ Object

    To create the X++ class and add to a managed code project, follow these steps:

    1. Open Microsoft Dynamics AX. 2. Open the AOT. 3. Right-click the Classes node and create a new class. 4. Rename the class to XppClassCalledFromManagedCode. 5. Create a method called getCustomerName that takes _CustAccount

    as a parameter and returns the customer name.

    public Name getCustomerName( CustAccount _CustAccount) { return CustTable::find(_CustAccount).name(); }

    6. Save and compile the class.

    Step by Step: Managed Code

    To create a managed code project, follow these steps:

    1. Start Visual Studio. 2. Create new project of type ClassLibrary by clicking File >

    New > Project. 3. Select Visual C# and then select Class Library. 4. Enter DemoManagedCode into the Name field and then click OK. 5. Right-click the DemoManagedCode project and then click Add

    DemoManagedCode to AOT. 6. Right-click Class1 in the project. 7. Select Rename and call the class ManagedCodeVSClass. 8. In Visual Studio find XppClassCalledFromManagedCode in the

    Application Explorer. 9. Add the class to the Model Project. 10. Create a C# method called getCustomerName that returns the

    customer name. 11. Call the ManagedCodeXPPClass class from inside

    ManagedCodeVSClass. 12. Call the XppClassCalledFromManagedCode class from inside

    ManagedCodeVSClass.

    public string getCustomerName() { XppClassCalledFromManagedCodeCustName = new XppClassCalledFromManagedCode(); return CustName.getCustomerName("1000"); }

    3-12

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    13. Build the project. 14. Make sure that the DemoManagedCode project is added to the

    Application Explorer and AOT in Microsoft Dynamics AX 2012.

    Step by Step: Research Object Relations

    To research object relations using the Cross-reference tool, follow these steps:

    1. Open the AOT. 2. Expand the C Sharp Projects node under the Visual Studio

    Projects node and select DemoManagedCode. 3. Right-click DemoManagedCode and select Add-Ins > Cross-

    reference > Update. 4. Expand the Classes node and select

    XppClassCalledFromManagedCode. 5. Right-click XppClassCalledFromManagedCode and select Add-

    Ins > Cross-reference > Update. 6. Select Add-Ins > Cross-reference > Used by. 7. Make sure that the Cross-reference tool shows the relationship

    between X++ and managed code objects.

    3-13

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Summary The new Visual Studio integration provides a set of tools and functions that support the modeling of business application elements as well as the ability to develop business logic in managed code. Some main improvements include the following:

    Support development in managed code. Browse AX metadata from inside Visual Studio. Store Visual Studio projects in the AX model store/repository. Model Reporting Services reports and write managed reporting

    business logic. Develop Enterprise Portal web controls. Develop and debug managed code integrating with AX, using

    proxies and events. Debug server side batch and services X++ code. Source control is available on Visual Studio projects and contained

    items that were added to the AOT.

    3-14

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Test Your Knowledge 1. Which of the following user interface components help developers to group

    relevant elements that make up a solution in Visual Studio?

    ( ) Microsoft Dynamics AX Model Project ( ) Microsoft Dynamics AX Application Explorer ( ) Microsoft Dynamics AX Model Editor

    2. Which of the following statements describes an improvement made to the new Business Connector? (Select all that apply)

    ( ) You can call out from X++ code to managed code and also call back into X++.

    ( ) You can use functionality that is provided by the Microsoft Dynamics AX stack.

    ( ) You can save C# or Visual Basic VB class library projects to the AOT.

    ( ) You can customize managed code projects using the various layers.

    3. Which of the following statements is true?

    ( ) Managed Code is deployed manually from within Visual Studio. ( ) Managed Code can be deployed automatically to physical locations on

    the client and server.

    3-15

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    Quick Interaction: Lessons Learned Take a moment and write down three key points you have learned from this chapter

    1.

    2.

    3.

    3-16

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • Chapter 3: Development with Visual Studio

    Solutions Test Your Knowledge

    1. Which of the following user interface components help developers to group relevant elements that make up a solution in Visual Studio?

    () Microsoft Dynamics AX Model Project ( ) Microsoft Dynamics AX Application Explorer ( ) Microsoft Dynamics AX Model Editor

    2. Which of the following statements describes an improvement made to the new Business Connector? (Select all that apply)

    () You can call out from X++ code to managed code and also call back into X++.

    () You can use functionality that is provided by the Microsoft Dynamics AX stack.

    () You can save C# or Visual Basic VB class library projects to the AOT.

    () You can customize managed code projects using the various layers. 3. Which of the following statements is true?

    ( ) Managed Code is deployed manually from within Visual Studio. () Managed Code can be deployed automatically to physical locations

    on the client and server.

    3-17

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

  • What's New - Technical in Microsoft Dynamics AX 2012 for Development

    3-18

    Microsoft Official Training Materials for Microsoft Dynamics

    Your use of this content is subject to your current services agreement

    Chapter 3: DEVELOPMENT WITH VISUAL STUDIOObjectivesIntroductionVisual Studio ToolsMicrosoft Dynamics AX Model ProjectScenario: Create a Microsoft Dynamics AX Model ProjectProcedure: Create a Microsoft Dynamics AX Model ProjectMicrosoft Dynamics Application ExplorerProcedure: Add ElementsProcedure: Remove ElementsMicrosoft Dynamics AX Model EditorProcedure: Edit Elements

    Lab 3.1 - Visual Studio ToolScenarioChallenge Yourself!Need a Little Help?Step by Step

    Managed CodeScenario: Adding a Managed Code ProjectProcedure: Adding a Managed Code ProjectProxiesScenario: Adding an AOT ObjectProcedure: Adding an AOT ObjectDeploymentCross-Reference ToolScenario: Research AOT ObjectsProcedure: Research AOT Objects

    Lab 3.2 - Managed CodeScenarioChallenge Yourself: Create X++ ObjectChallenge Yourself: Managed CodeChallenge Yourself: Research Object RelationsNeed a Little Help?Step by Step: Create X++ ObjectStep by Step: Managed CodeStep by Step: Research Object Relations

    SummaryTest Your KnowledgeQuick Interaction: Lessons LearnedSolutions