Dynamics Search Engine

Tuesday, September 30, 2008

Microsoft® DynamicsTM Ax container manipulation using X++

Note: There is no warranty in the code written below. Use at your own risk.

Overview
Container is a built-in data type, X++ supports a number of functions to manipulate the contents of containers. This topic describes the built-in functions for manipulating containers. In other way we can say X++ has a general data type called a container that can be regarded as a dynamic untyped array of primitive data types, containers, and arrays. Containers can be used to hold a list of items of different types.

Allocation of containers
Containers are automatically allocated, when a container variable is used which means that you do not have to create a container using new.

Disposal of containers
To explicitly dispose the contents of a container use the connull function.
void DisposalMethod()
{
container con;
con = connull( );
}


Length
When you operate on a container, you often need to know how many items it contains. The conlen function returns the number of items in the container.
void LengthMethod()
{
container con;
//gives output 0 as there are initially no elements in a container
print conlen(con);
}


Finding a sequence of elements
To locate a sequence of items in a container, use the confind function. confind takes a container and one or more items as arguments. The function returns 0 (the item was not found) or the item’s sequence number.
void SequenceMethod()
{
container con = [100,110, ”Hello World”];
int i;
i = confind( con, “Hello World”); //i has the value of Hello World
}


Insertion
Sometimes you need to insert some items in a container. Use the conins function, which takes a variable number of arguments: the container, position, and the items to be inserted.
void InsertionMethod()
{
container con;
con = conins(con,10,”Hello Testing”);
}


Deletion
To delete one or more items from a container, use the condel function. condel takes three arguments: the container, the start position for deletion, and the number of items to be deleted.
void DeletionMethod()
{
container con = ["Hello", 100, 5.55);
con = condel(con,1,2);
}


Replacement
To replace an item in a container, use the conpoke function. conpoke takes a variable number of arguments: the container, the position (to be poked), and the new item.
void ReplacementMethod()
{
container con = [10, 30.11, ”Hello”];
// Replaces the first item - 10 - with “Hello World”
con = conpoke(con, 1, ”Hello World”);
}


Extraction
A container allows you to hold a number of items, possibly of different types, and then use them in some other context. To use the items, you need to be able to extract them from the container. This is the purpose of the conpeek function. conpeek takes two arguments: the container and the position to be peeked.


The conpeek function automatically converts the peeked item into the expected return type. Strings can automatically be converted into integers and vice versa.
void ExtractionMethod()
{
str 10 string;
container con = [10, 30.11, ”Good Testing”];
// Extracts the real 30.11 and converts it into a string: “30.11”
string = conpeek(con,2);
}


You can extract more than one element from a container with a composite assignment:
void ExtractionMethod1()
{
str 10 string;
int i;
real rl;
container con = [10,30.11,”Hello”];
[il,r, string] = con; // Extracts 10 into i, 30.11 into rl and “Hello” into string

}

Monday, September 29, 2008

Microsoft® DynamicsTM AX 2009 Known Issues

This Known Issues document contains information about known issues in the May 2008 release of Microsoft® DynamicsTM AX 2009.
To see the issues click on the link below (Extranet login is required).
Microsoft Dynamics AX 2009 Known Issues
Here you can see the issues and solutions.
The above link can be changed without any notice.

Saturday, September 20, 2008

How to use CLR Interop with Dynamics Ax 4.0

This article will explain you how to use CLR Interop with Dynamics Ax 4.0.

Write your business logic in .Net environment and use that within Dynamics Ax.

It assume that you are familiar with Microsoft Dynamics Ax and Visual Studio .Net
You should have Ax 4.0 & Visual Studio .Net installed on your system.
There is No warranty on this article, use at your own risk. If it’s useful then refer to others.

.NET CLR Interop Overview
Classes in assemblies that are managed by the common language runtime (CLR) can be accessed in X++ code. This feature of Microsoft Dynamics AX is called common language runtime (CLR) interoperability, or CLR interop.
The CLR interop feature works only in the direction from X++ calling into CLR managed assemblies. It does not support calling X++ classes from a CLR managed assembly.
CLR interop is useful when you want your X++ code to access the functionalities in a CLR managed assembly.


1.
Open Visual Studio and create a new project. During creating a new project area, choose programming language Visual C# and template Class library. I have given the project name TalkToDotNet.








Figure 1.















Figure 2.

2.
By default you will get a standard class template as below:
using System;
using System.Collections.Generic;
using System.Text;

namespace TalkToDotNet
{
public class Class1
{
}
}



3.
Now add the following lines within Class1
public string CombinedMsg(string _msg)
{
string message1;
message1 = _msg;
return message1 + "From .Net: I am fine";
}

After addition the above lines the class1 will look like:

using System;
using System.Collections.Generic;
using System.Text;

namespace TalkToDotNet
{
public class Class1
{
public string CombinedMsg(string _msg)
{
string message1;
message1 = _msg;
return message1 + "From .Net: I am fine";
}
}


}



The above class is having a method called CombinedMsg which takes a string parameter and add "From .Net: I am fine" string with the parameter string.

4.
Now go to the project explorer window and select the project. Right click on the project and click on Properties. You will get the window as below.


Figure 3.

5.
Click on Signing Tab and then check the check box Sign the assembly.


Figure 4.

6. Choose New from the drop down box as shown below.


Figure 5.

7.
It will ask you for user id and password to protect your business logic. This is optional. You may ignore.

Figure 6.


8.
Click on Build menu then Build Solution.

Figure 7.

If any error is there then you will be prompted otherwise you will get the successful message. Now copy the dll from your project area and paste it to Bin directory of your Ax client folder.


9.
Now open your Ax application.


10.
Open AOT, select the References node and right click on it. On the context menu click on Add reference.

Figure 8.


11.
You will get the window as below. Click on Browse button and go to the Bin folder of your Ax client folder.

Figure 9.




Figure 10.




Figure 11.


12.
See the dll is added.

Figure 12.

13.
The dll is now added in the references node of AOT.


Figure 13.


14.
Now create a job in Ax and call the dll.

Figure 14.



Figure 15.


15.
The job is as below.

Figure 16.


static void TalkToDotNet(Args _args)
{
str strval;
TalkToDotNet.Class1 testCls = new TalkToDotNet.Class1();
strval = testCls.CombinedMsg('From Ax: How are you? ');
print strval;
pause;
}

16.
See the print message below. It takes a string message from Ax and adds it with the message returned by dll.

Figure 17.

Hope it would a helpful article for you guys.