Ax2012 Enus Deviii 05
Ax2012 Enus Deviii 05
Introduction
With Visual Studio tools built specifically for Microsoft Dynamics® AX
development, managed code that seamlessly uses elements from the AOT and
interacts with existing Microsoft Dynamics AX business logic can be written.
5-1
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Scenario
Isaac, the systems developer, has been asked to write an event handler for a
Microsoft Dynamics AX event. Instead of X++, Isaac has been asked to write
this event handler in managed code, using Visual Studio.
Application Explorer
The Application Explorer in Visual Studio is a representation of the Microsoft
Dynamics AX AOT. It is organized in the same structure as the AOT.
Like other window panes in Visual Studio, it can be toggled between visible and
invisible. To show the Application Explorer, select it from the View menu in
Visual Studio. The Application Explorer can also be docked or undocked, like
other panes in Visual Studio.
After discussing how to create a project, the Application Explorer can be used
to leverage AOT elements within Visual Studio.
5-2
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
Types of Projects
There are three types of Visual Studio projects that can be used to develop
customizations for Microsoft Dynamics AX:
The Report modeling and Enterprise Portal Web application project types
have their own templates provided under the Microsoft Dynamics AX template
group. These topics are more thoroughly covered in the "Reporting in Microsoft
Dynamics AX 2012" and "MorphX and Enterprise Portal Development in
Microsoft Dynamics AX 2012" courses.
5-3
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Once dropped into the Solution Explorer, a node representing the element will be
in the project. These are referred to as proxies.
To demonstrate the connectivity with the AOT, the following code could now be
written in the C# class library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public string GetCustomerPaymentMode(string
accountNum,
string
dataAreaId)
{
string paymentMode = String.Empty;
CustTable custTable = new CustTable();
accountNum);
if (custTable.Found)
{
// Get the value for the customer's payment
mode.
paymentMode = custTable.PaymMode;
}
return paymentMode;
}
}
}
5-4
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
This example illustrates how the CustTable element is now used in the C# code.
An object of type CustTable is instantiated and used to fetch a record from the
database. Notice the use of a method on the table object: findByCompany().
Also notice that Visual Studio accepts the use of table fields, like
CustTable.PaymMode, as well as table methods.
The method created is empty, and ready for the pre-event code to be added. Do
not change the name of the method, or the event handler will not work.
5-5
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
The following are the basic steps for deploying managed code:
The following deployment properties are available in the Properties pane for the
project:
• Deploy to Server
• Deploy to Client
• Deploy to EP
• Deploy to SSRS
Deploy to Server
If the Deploy to Server property is set to Yes, the system deploys the project
output (a DLL, for example) by copying it to the server's \bin directory. The
server \bin directory might be found at a file location such as the following:
After the managed code has been deployed, the AOS must be restarted so that the
assembly can be loaded by the AOS. If you have hot swapping enabled, the
AOS does not have to be restarted. Hot swapping allows multiple application
domains on a single AOS, allowing new versions of managed code to be
deployed and be immediately available to any new client connections. Hot
swapping can be enabled by following these steps:
5-6
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
Deploy to Client
If the Deploy to Client property is set to Yes, the system deploys the project
output (a DLL, for example) by copying it to the client \bin directory. The client
\bin directory might be found at a file location such as the following:
5-7
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
5-8
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
Scenario
Before any managed code can be written, you need to create a Managed Code
project in Visual Studio that can use the Microsoft Dynamics AX integrated tool
set. Create this managed code project, and add the SalesTableType X++ class to
the project.
Challenge Yourself!
Step by Step
5-9
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Scenario
The event that you have been asked to handle, is the ValidateWrite method on
the SalesTableType (called to validate a SalesTable record before it is written).
You have been asked to create a post-event handler using managed code. You
will also need to create a managed code project to hold this event handler (the
project created in Lab 5.1 can be used for this purpose).
Challenge Yourself!
Step by Step
5-10
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
Summary
By using the integrated Microsoft Dynamics AX tool set inside Visual Studio,
developers can now write managed code in any .NET language to enhance or
modify Microsoft Dynamics AX business logic. The Application Explorer tool
offers a development environment similar to that within Microsoft Dynamics
AX, making switching between the two easier and more familiar.
5-11
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
1. What type of Visual Studio projects can be used to integrate with Microsoft
Dynamics AX?
2. What key step in creating a managed code project will connect the project
with the AX tool set within Visual Studio?
3. What four deployment properties are available for a Visual Studio project
that has been added to the Microsoft Dynamics AX AOT?
5-12
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
4. What needs to happen before the Visual Studio debugger will activate on
breakpoints inside managed code called from the Microsoft Dynamics AX
client or server?
5-13
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
1.
2.
3.
5-14
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 5: Visual Studio Integration
Solutions
Test Your Knowledge
1. What type of Visual Studio projects can be used to integrate with Microsoft
Dynamics AX?
MODEL ANSWER:
2. What key step in creating a managed code project will connect the project
with the AX tool set within Visual Studio?
MODEL ANSWER:
3. What four deployment properties are available for a Visual Studio project
that has been added to the Microsoft Dynamics AX AOT?
MODEL ANSWER:
4. What needs to happen before the Visual Studio debugger will activate on
breakpoints inside managed code called from the Microsoft Dynamics AX
client or server?
MODEL ANSWER:
5-15
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
5-16
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement