Monday 11 February 2013

Saturday 9 February 2013

How to create a Factbox in Dynamics Ax 2012



Displaying a factbox on a form is one of the things that is introduced in Dynamics Ax 2012. In this article I give you the details how to create a factbox. Creating a factbox exists of three parts. The first one is create the query, the second one is create the part and the third one is adding the factbox to a list page.

Create the query
  • Right click in the AOT on the query node and select new query
  • Give your query a name
  • Drag the table of which you want to display information form to the datasource of the query
  • Set the dynamic property on the fields node to Yes, this includes all fields to the query
  • Save your changes

Create the part
  • Expand the Parts node in the AOT
  • Do a right click on Info Parts and select New Info Part
  • Give the info part a name by filling the name property and if you want you can set the caption of the form
  • Set the Query property the name of the query you have just created
  • Richt-click the layout node in the info part, and select New Group
  • Set the repeating in the new group to Yes
  • Create new field by doing a right-click on the new group
  • On this new field, set the datasource property to the table of the query and set the datafield to a field you want to display

Adding a factBox to a list page
  • First create a menuitem for the part you have just created by draging the part to the menu items - display node in the aot
  • After that drag the menuitem to the parts node in the on the form on which you want to display the factbox
  • Set the datasourcerelation to the correct EDT on the property sheet for the part
  • Save your changes and you factbox should be visible on the form

Learn C# (C-Sharp) step by step



Welocme to the Learn C-Sharp step by step section. C# is a high programming language. It has taken the best features from C++ and JAVA. C# is probably the best programming language.
 
C# (C sharp) basics:

1. How to write on screen in C#.
Console.WriteLine("I have been studying C# for 4 weeks!");
This will appear on screen, and will disappear immediately. So, We are writing another statement.
Console.WriteLine("I have benn studying C# for 4 weeks!");
Console.ReadLine();
Now it will remain on screen, unless we press Enter key.
Here we see that we can write letters, numbers and special characters (#) on screen.

String: String is name of variable, and it could be anything letters, numbers and special charecters. We can use string for numbers also, but when we need any arithmetical operation, we use integers, decimals etc as variables

2. String Concatenation:
We can add two strings, called string concatenation. For example, we are adding first name and second name to get full name.
string a = "John ";
string b = "Smith";
string c = a + b;
Console.WriteLine(c);
Console.ReadLine();
3. Adding two numbers:
int a=10;
int b=12;
int c=a+b;
Console.WriteLine(c);
Console.ReadLine();
Here, we use integers as variables, because we want to add them (arithmetical operation).
Integers does NOT take fractional (decimal) values. If we want to perform arithmetical operation of fractional values; we can take double as variables.
double a = 3.4;
double b = 5.2;
double c = a + b;
Console.WriteLine(c);
Console.ReadLine();
4. How C# take input:
The program will take input from user, and will display it on screen
string name = Console.ReadLine();
Console.WriteLine(name);
Console.ReadLine();
Integer as input:
Input is always in string. So for integer, we need to convert it first.
int number = Convert.ToInt16(Console.ReadLine());
Console.WriteLine(number);
Console.ReadLine();
Remember: As the input is always in string, so for integers as input we need to convert it first.

5. Take two inputs (integers) from user and add them.
int number1 = Convert.ToInt16(Console.ReadLine());
int number2 = Convert.ToInt16(Console.ReadLine());
int number3 = number1 + number2;
Console.WriteLine(number3);
Console.ReadLine();
6. Take two inputs (string) from user, and add them.
string firstname = Console.ReadLine();
string lastname = Console.ReadLine();
string fullname = firstname + lastname;
Console.WriteLine(fullname);
Console.ReadLine();
As, input is always in string, so we did not need to convert it.

Conditional Statements in C#:
  • The if, if / else, if / else if / else Statement
  • The switch Statement

The if Statement:
Construction:
if (condition)
{statement}
For example,
int a = Convert.ToInt16(Console.ReadLine());
if (a > 10)
{Console.WriteLine("The number is greater than 10");
Console.ReadLine();
The if / else Statement:
Construction:
if (condition)
{statement}
else
{statement}
For example,
int a = Convert.ToInt16(Console.ReadLine());
if (a > 10)
{Console.WriteLine("The number is greater than 10");}
else
{ Console.WriteLine("The number is 10 or less than 10");}
Console.ReadLine();
The if / else if / else Statement- (also called nested if)
Construction:
if (condition)
{statement}
else if (condition)
{statement}
else
{statement}
For example,
int a = Convert.ToInt16(Console.ReadLine());
if (a > 10)
{Console.WriteLine("The number is greater than 10");}
else if (a == 10)
{Console.WriteLine("The number is 10");}
else
{ Console.WriteLine("The number is less than 10");}
Console.ReadLine();
NOTE: We write = two times.

The switch Statement:
Construction:
switch (integer a)
{
case 1:
statement
break;
case 2:
statement
break;
default:
statement
break;
}
NOTE: The default in switch statement is equaivalent to else in if statement.
For example,
int week = Convert.ToInt16(Console.ReadLine());
switch (week)
{
case 1:
Console.WriteLine("Monday");
break;
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
case 4:
Console.WriteLine("Thursday");
break;
case 5:
Console.WriteLine("Friday");
break;
case 6:
Console.WriteLine("Saturday");
break;
case 7:
Console.WriteLine("Sunday");
break;
default:
Console.WriteLine("NOT KNOWN");
break;
}
Console.ReadLine();
The for loop in C#
Construction
for (initial point; ending point; increament)
{
Statement(s)
}
For example, the following program will write counting from 1 to 20.
for (int i = 1; i < 21; i++)
{
Console.WriteLine(i);
}
Console.ReadLine();
Q. Write table of 2 using for loop in C#.
for (int i = 1; i < 11; i++)
{
int tab = 2 * i;
Console.WriteLine(tab);
}
Console.ReadLine();
Q. Write a program that print even numbers from 1 to 100.
for (int i = 1; i < 101; i++)
{
if (i % 2 == 0)
{
Console.WriteLine(i);
}
}
Console.ReadLine();
Q. Write a program that take input from user, and write table of that number.
Console.WriteLine("Enter a number:");
int num = Convert.ToInt16(Console.ReadLine());
for (int i = 1; i < 11; i++)
{
int tab = i * num;
Console.WriteLine(tab);
}
Console.ReadLine();
Q. Write a program in C sharp, to find the factorial of 5.
int fact = 1;
for (int i = 5; i > 0; i--)
{
fact=fact*i;
}
Console.WriteLine(fact);
Console.ReadLine();
Q. Write a program that take input from user, and find factorial of that number.
Console.WriteLine("Enter a number:");
int num = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Its factorial is:");
int fact = 1;
for (int i = num; i > 0; i--)
{
fact=fact*i;
}
Console.WriteLine(fact);
Console.ReadLine();
The while Loop
Construction:
while (condition)
{
statement(s)
}
Q. Write a program in C# using while loop, that take a number from user and return cube of that number. And the program ends when the input is 11.
int num = Convert.ToInt16(Console.ReadLine());
int cube = num * num * num;
while (num != 11)
{
Console.WriteLine(cube);
break;
}
Console.ReadLine();
Q. Write a program that starts from 0, increase 1 by 1, and end before 10 using while loop in C Sharp.
int number = 0;
while (number < 10)
{
Console.WriteLine(number);
number = number + 1;
}
Console.ReadLine();
The do - while loop
Construction
do
{
statement(s)
}
while
{
statement(s)
}
Q. Write a program in C Sharp using do - while loop, that take a number, and increase it 2 by 2, and ends before 30.
int num = Convert.ToInt16(Console.ReadLine());
do
{
Console.WriteLine(num);
num = num + 2;
}
while (num < 30);
Console.ReadLine();
Array in C#
Construction
variable type [] variable name = new variable type [length]
Array of type integer with constant values
int[] myarray = new int[3] { 2, 5, 9 };
Console.WriteLine(myarray[0]);
Console.ReadLine();
NOTE:index 0 inside Console.WriteLine statement represents index of array, that is 2.
In the above myarray; index 0 = 2, index 1 = 5, index 2 = 9.
If we replace 0 by 1, the program will show 5, and for 2, the program will show 9.

Array of type string with constant values
string[] name = new string [3] { "Bilal", "Sohail", "Afzal" };
Console.WriteLine(name[0]);
Console.ReadLine();
Q. Write an array in C# of type integer that take 3 numbers as input (the program must close after taking 3 inputs).
int[] myarray = new int[3];
myarray[0] = Convert.ToInt16(Console.ReadLine());
myarray[1] = Convert.ToInt16(Console.ReadLine());
myarray[2] = Convert.ToInt16(Console.ReadLine());
Console.WriteLine(myarray);
Console.ReadLine();
Q. Write an array in C Sharp of type string that take 3 strings (names) as input (the program must ends after taking 3 inputs).
string[] name = new string[3];
name[0] = Console.ReadLine();
name[1] = Console.ReadLine();
name[2] = Console.ReadLine();
Console.WriteLine(name);
Console.ReadLine();
Q. Write an array in C# of type integer that take 10 numbers as input (Use for loop for simplicity).
int[] myarray = new int[10];
for (int i = 0; i < 10; i++)
{
myarray[i] = Convert.ToInt16(Console.ReadLine());
}
Console.WriteLine(myarray);
Console.ReadLine();
Q. Write a program in C Sharp that take 10 inputs from user, and show their sum.
int[] myarray = new int[10];
for (int i = 0; i < 10; i++)
{
myarray[i] = Convert.ToInt16(Console.ReadLine());
}
int a = 0;
for (int j = 0; j < 10; j++)
{
a = a + myarray[j];
}
Console.WriteLine(a);
Console.ReadLine();
Q. Write a program in C# that take 10 numbers, and show their average (input could be decimal or fractional value also).
double[] myarray = new double[10];
for (int i = 0; i < 10; i++)
{
myarray[i] = Convert.ToInt16(Console.ReadLine());
}
double a = 0;
double b = 0;
for (int j = 0; j < 10; j++)
{
a = a + myarray[j];
b = a / 10;
}
Console.WriteLine(b);
Console.ReadLine();
Introduction to Windows Forms Application

Q. Take two inputs from user (first name and second name) and concatenates them and print it, using windows forms application in C#.
For this, take 2 textboxes and 1 button from toolbox menue.
string firstname = textBox1.Text;
string secondname = textBox2.Text;
string fullname = firstname + secondname;
MessageBox.Show(fullname);
Q. Take 2 inputs from user and add them using windows forms application in C#.
int a = Convert.ToInt16(textBox1.Text);
int b = Convert.ToInt16(textBox2.Text);
int c = a + b;
MessageBox.Show(Convert.ToString(c));
Q. Write a program that take input from user and show whether the number is odd or even, using windows forms application in C Sharp.
For this, take 1 textbox and 1 button.
int number = Convert.ToInt16(textBox1.Text);
if (number % 2 == 0)
{
MessageBox.Show("EVEN");
}
else
{
MessageBox.Show("ODD");
}
Functions in C#
Construction
output type (input type)
{
return (program);
}

Now call the function

output type = function name;
The following example will make the matter clear.

Q. Write a function that take 2 numbers and add them using windows forms application in C#.
Function
int add(int a, int b)
{
return (a + b);
}
Now, call the function
int c = add(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text));
MessageBox.Show(Convert.ToString(c));
Q. Write a function in C Sharp which takes three number as input parameter and return the largest of three.
Function
int largest(int a, int b, int c)
{
if (a > b && a > c)
{
return a;
}
else if (b > a && b > c)
{
return b;
}
else
{
return c;
}
}
Call the function
int result = largest(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text), Convert.ToInt16(textBox3.Text));
MessageBox.Show(Convert.ToString(result));
Q. Write a program in C# that take Temperature in Fahrenheight, and convert it to Centigrate.
Console.WriteLine("Enter Temperature in Fahrenheight:");
double ftemp = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Equivalent Temperature in Centigrate is:");
double ctemp= (ftemp-32) * 5 / 9;
Console.WriteLine(ctemp);
Console.ReadLine();
Q. Write a program in C Sharp that take Month and Date, and show number of days from the start of the year to that date. Console.WriteLine("Enter Month");
Console.WriteLine("Enter Date");
int b = Convert.ToInt16(Console.ReadLine());
int c = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Number of days from the start of the year are:");
int a = 0;
int d = 0;
int[] month = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
for (int i = 0; i < b - 1; i++)
{
a = a + month[i];
d = a + c;
}
Console.WriteLine(d);

Finding String Length in C-Sharp

Q. Write a program in C# that take string input, and print its number of characters.

string name = Console.ReadLine();
Console.WriteLine(name.Length);
Console.ReadLine();

Q. Write a program in C Sharp that take a sentense as input, and show the number of "a" used in the sentense.

string name = Console.ReadLine();
int counter = 0;
for (int i = 0; i < name.Length; i++)
{
if (name[i] == 'a')
{
counter++;
}
}
Console.WriteLine(counter);
Console.ReadLine();

Q. Write a program in C# taht take name and password. If the name and password are correct, the program show "you are logged in", otherwise, "incorrect name or password".

Console.WriteLine("Enter your Name");
Console.WriteLine("Enter your Pswrd");
string name = Console.ReadLine();
string pswrd = Console.ReadLine();
string myname = "bilal";
string mypswrd = "123456";
if (name == myname && pswrd == mypswrd)
{
Console.WriteLine("You are logged in");
}
else
{
Console.WriteLine("Incorrect name or pswrd");
}
Console.ReadLine();
Sorting Arrays in C Sharp
Q. Write a string array of length 3, and sort them.

string[] name = new string[] { "We", "He", "Us"};
Array.Sort(name);
foreach (string i in name)
{
Console.WriteLine(i);
}
Console.ReadLine();

Q. Write a string array in C# that take 5 inputs, and sort them.

string[] name = new string[5];
for (int i = 0; i < 5; i++)
{
name[i] = Console.ReadLine();
}
Array.Sort(name);
foreach (string i in name)
{
Console.WriteLine(i);
}
Console.ReadLine();

Q. Write an array in C Sharp of length 3, and sort it.

int[] numbers = new int [] { 4, 3, 8, 0, 5 };
Array.Sort(numbers);
foreach (int i in numbers)
{
Console.WriteLine(i);
}
Console.ReadLine();

Q. Write a program in C# that take 5 integers, and sort them.

int[] numbers = new int[5];
for (int i = 0; i < 5; i++)
{
numbers[i] = Convert.ToInt16(Console.ReadLine());
}
Array.Sort(numbers);
foreach (int i in numbers)
{
Console.WriteLine(i);
}
Console.ReadLine();
Print Pattern in C-Sharp
Q. Print * 10 times vertically usinf C# Console Application.

for (int i = 1; i < 11; i++)
{
Console.WriteLine("*");
}
Console.ReadLine();

Q. Print * 10 times Horizontally usinf C# Console Application.

for (int i = 1; i < 11; i++)
{
Console.Write("*");
}
Console.ReadLine();

Q. Print * 10 times Horizontally with spaces between them usinf C# Console Application.

for (int i = 1; i < 11; i++)
{
Console.Write("* ");
}
Console.ReadLine();

Q. Write a program in C# that take string input and print the result vertically.

string name = Console.ReadLine();
for (int i = 0; i < name.Length; i++)
{
Console.WriteLine(name[i]);
}
Console.ReadLine();

Q. Print the following pattern using C# Console Application.
*
**
***
****
*****


for (int i = 1; i < 6; i++)
{
for (int j = 1; j <= i="" j="" br="">{
Console.Write("*");
}
Console.WriteLine("");
}
Console.ReadLine();

Q. Print the following pattern using C-Sharp Console Application.
*****
****
***
**
*


for (int i = 5; i > 0; i--)
{
for (int j = 1; j {
Console.Write("*");
}
Console.WriteLine("");
}
Console.ReadLine();

Q. Print pyramid using C# Console Application, like this:
    *
   * *
  * * *
 * * * *
* * * * *
<= i="" j="" br=""><= i="" j="" br="">for (int i = 1; i < 6; i++)
{
for (int j = 4; j >= i; j--)
{
Console.Write(" ");
}
for (int k = 1; k <= i="" k="" br="">{
Console.Write("* ");
}
Console.WriteLine("");
}
Console.ReadLine();

Tuesday 18 December 2012

Database synchronization


Whenever the object data model in Dynamics AX is modified, database synchronization is required. In Dynamics AX, this typically occurs automatically. However, at times it does not and at times there may be a need to manually synchronize the data model from Dynamics AX tables, fields, base enums, and extended data types, with the database. For example, if extended data types, base enumerators, tables, or field information is changed in Dynamics AX, the SQL database tables must be updated to be in sync. This may occur when the licensing schema changes in an environment or a modification is made. It is recommended to run this tool often to ensure that the data model in Dynamics AX is in sync with SQL. The following steps describe this process:
  1. To synchronize Dynamics AX against SQL tables, run the SQL administration tool in Administration | Periodic | SQL administration.
  2. Click on the Table actions button and click on Check/Synchronize to check if the Dynamics AX data model is in sync with SQL tables.
  3. Then, pay special attention to any errors and warnings as they can signify data inconsistency and possible data loss. Information messages are not a concern since they do not affect data integrity or structure. If errors or warnings do exist, they must be fixed. Typically, running the synchronization fixes these issues. Since synchronization may delete fields in SQL tables, data may also be lost. Therefore, before performing synchronization, back up the Dynamics AX database in SQL. Once the database is backed up, click on the Continue button to synchronize the database.
    In some instances, manual intervention may be required. For example, in common cases when tables need to be re-indexed, you would browse the tables in SQL Management Studio and delete the deprecated indexes. Once complete, run the synchronization utility again.
  4. If you are successful, there will be no message. However, if the synchronization fails or encounters errors, an Infolog window will appear with the errors. This may require manual intervention such as going into SQL Server and modifying the data manually.

To export / import data from within AX, definition groups approach should be used.

If want to take the data backup then follow the below procedure and by means of this you can take the backup of the compnay data in which you currently working on
  • Goto Administration module
  • Under periodic
  • expand Data export/import menu
  • in that select  'Export to'
  • give the location where you want to store the data
after this procedure the system will generate 2 files (DAT and DEF)

Wednesday 12 December 2012

Import Data into Sql Server From Excel Spreadsheet


I have an Excel sheet now I need to insert data from that sheet into SQL Server 2008.
I need to create a temp table and insert data into that table. The database name is Employee
Can you pls provide me the syntax for achieving it.

A simple search: http://support.microsoft.com/kb/321686

Probably easiest is

SELECT *
INTO #tmptable
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [SheetName$])

 

 Apart from using DTS and Export wizard, we can also use this query to export data from SQL Server2008 to Excel & Excel to Server 2008

Create an Excel file named testing having the headers same as that of table columns and use these queries

1 Export data to existing EXCEL file from SQL Server table
insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
    'Excel 8.0;Database=D:\testing.xls;', 
    'SELECT * FROM [SheetName$]') select * from SQLServerTable


2 Export data from Excel to new SQL Server table

select * 
into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
    'Excel 8.0;Database=D:\testing.xls;HDR=YES', 
    'SELECT * FROM [Sheet1$]')


3 Export data from Excel to existing SQL Server table
Insert into SQLServerTable Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
    'Excel 8.0;Database=D:\testing.xls;HDR=YES', 
    'SELECT * FROM [SheetName$]')


4 If you dont want to create an EXCEL file in advance and want to export data to it, use

EXEC sp_makewebtask 
 @outputfile = 'd:\testing.xls', 
 @query = 'Select * from Database_name..SQLServerTable', 
 @colheaders =1, 
 @FixedFont=0,@lastupdated=0,@resultstitle='Testing details'
(Now you can find the file with data in tabular format)


5 To export data to new EXCEL file with heading(column names), create the following procedure

create procedure proc_generate_excel_with_columns
(
 @db_name varchar(100),
 @table_name varchar(100), 
 @file_name varchar(100)
)
as

--Generate column names as a recordset
declare @columns varchar(8000), @sql varchar(8000), @data_file varchar(100)
select 
 @columns=coalesce(@columns+',','')+column_name+' as '+column_name 
from 
 information_schema.columns
where 
 table_name=@table_name
select @columns=''''''+replace(replace(@columns,' as ',''''' as '),',',',''''')

--Create a dummy file to have actual data
select @data_file=substring(@file_name,1,len(@file_name)-charindex('\',reverse(@file_name)))+'\data_file.xls'

--Generate column names in the passed EXCEL file
set @sql='exec master..xp_cmdshell ''bcp " select * from (select '+@columns+') as t" queryout "'+@file_name+'" -c'''
exec(@sql)

--Generate data in the dummy file
set @sql='exec master..xp_cmdshell ''bcp "select * from '+@db_name+'..'+@table_name+'" queryout "'+@data_file+'" -c'''
exec(@sql)

--Copy dummy file to passed EXCEL file
set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> "'+@file_name+'"'''
exec(@sql)

--Delete dummy file 
set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
exec(@sql)

After creating the procedure, execute it by supplying database name, table name and file path

EXEC proc_generate_excel_with_columns 'your dbname', 'your table name','your file path'




Import Data into Sql Server From Excel Spreadsheet using SQLBulkCopy class


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Common;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Connection String to Excel Workbook
            string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Book1.xls;ExtendedProperties=""Excel 8.0;HDR=YES;"";IMEX=1;";

            // Create Connection to Excel Workbook
            using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
            {
                OleDbCommand command = new OleDbCommand("Select ID,Data FROM [Data$]", connection);

                connection.Open();

                // Create DbDataReader to Data Worksheet
                using (DbDataReader dr = command.ExecuteReader())
                {
                    // SQL Server Connection String
                    string sqlConnectionString = "Data Source=.;Initial Catalog=Test;Integrated Security=True";

                    // Bulk Copy to SQL Server
                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
                    {
                        bulkCopy.DestinationTableName = "ExcelData";
                        bulkCopy.WriteToServer(dr);
                    }
                }
            }

        }
    }
}

Tuesday 11 December 2012

Executing .NET code in Dynamics AX 2009: Solving error “the selected file is not a valid .NET assembly”


To increase the functionality of AX is possible to execute .NET code.
In general terms the idea is create a .dll with the .NET code and after add the .dll as reference in AX. After that you’ll be able of execute the .NET code in AX.

Just follow these steps:

1. Create a new project (I’m going to use Visual Studio 2010):

VisualStudio2010_NewProject

VisualStudio_NewDLLProject

Please be sure that you’ve selected the .NET Framework 3.5: if you select a newest one AX won’t work with your .dll:

VS2010_NewProject_NETFramework35

2. Create the .NET code you want to execute:
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <p>using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
    namespace MyDLL
    {
        public class TestingMyDLL
        {
            public void showMessage()
            {
                 
                MessageBox.Show("Executing .NET code with AX!");
            }
        }
    }</p><p> </p>
3. Build the solution:

VS2010_BuildSolutionDLL

4. Locate the .dll generated under the Project folder:

VisualStudio2010_LocateDLLGenerated

And copy it in your AX testing environment. Take care with the path in which you copy your .dll: it has to be located in the “bin” directory of your AX installation (in my case C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin) otherwise AX will show you the following message:

DynamicsAX2009_AddingReferenceWarning

And maybe you wont use the library:

DynamicsAX2009_UsingDLLError

5. Import the dll into AX. Open the AOT and do right click in the References node and click ‘Add reference’:

DynamicsAX2009_AOTAddReference

DynamicsAX2009_AddingReferenceBrowse

DynamicsAX_ReferenceAdded

Press OK.

If you selected the .NET Framework 4 when creating the project in step 1 you’ll get this error trying to import the reference:The selected file is not a valid .NET assembly, therefore the refence cannot be added.

VS2010_NETFramework_Error

6. Create a new job/class in AX:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void testingNETCode(Args _args)
{
    MyDLL.TestingMyDLL          testingDll;
    InteropPermission           permission;
    ;
 
    try
    {
        permission = new InteropPermission(InteropKind::DllInterop);
        permission.assert();
 
        testingDll = new MyDLL.TestingMyDLL();
        testingDll.showMessage();
    }
    catch
    {
        error('Error executing DLL code');
    }
}

7. Run the job:

DynamicsAX_ExecutingNETCode_Job