resAppl macro when using images

Using images in Dynamics AX can sometimes be a painful experience, just keeping track of the Integer that represents the images is almost impossible. But with a macro called resAppl this becomes much easier, mainly because you, most of the time, can guess what commands to use to get the image you want. This makes it easier to remember between times you are going to use it, and above all it makes your code much easier to read and follow.
Continue reading resAppl macro when using images

Find files in a file directory

If you want to open or read files in a file directory you can use the following example to find the filenames.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  static void showFileName(Args _args)
  {
      int           handle;
      FilePath      filePath;
      FileName      FileName;
      ;
 
      filepath = "c:\\windows";
 
      [handle,filename] = 
       WinAPI::findFirstFile(filepath + "\\*.*");
 
      while (filename != "")
      {
          info(filepath + "\\" + filename);
          filename = WinAPI::findNextFile(handle);
      }
 
      WinAPI::findClose(handle);
  }

Intercompany with buf2buf

When discussing the “Basics of changecompany” we copied table records from one company to another through X++ code. Using buf2buf makes this is a lot easier.

Buf2buf is used to copy one recordbuffer to another:

       buf2buf(Common _from, Common _to)

If we apply this to the code we used in “Basics of changecompany” we get:
Continue reading Intercompany with buf2buf

date2int is date2num

Let’s say you have two dates and want to know how many days there are between these two dates. Searching through Dynamics AX developers help you will find that there is an explicit conversion called date2int. This sounds reasonable, we do want to convert our date to an int to get the number of days.

But if you try to use date2int you will find that this will generate an error when compiling that says:

This function has not been declared

Obviously date2int does not work as the developer help suggests. But what does?
Continue reading date2int is date2num

Basics of changecompany

The command changecompany is used to switch between companies in you Dynamics Ax environment through X++ code. This is the basics:

  // We are now in company FO
  changecompany("FO1")
  {
      // We are now in company FO1.
  }
  // Back in company FO

Let’s say that we start out in company FO and want to copy some data from company FO to company FO1. This is one way to do it.
Continue reading Basics of changecompany

How to create a new EventType

When using notifications in Dynamics AX we get different event types when setting up a new notification rule for different fields. If we try to create a notification rule for a date field, we get event types like “is due:”, “is due in:” and “has changed:”. If we create one for a string we get “has changed:” and “is set to:”.

Let’s say we want to create a new event type for fields containing numbers that checks if the number has doubled. This is how we do it.

We first need to create a new class that extends the EventTypeCUD class. We call our new class EventTypeCUDDoubleOrMore.
Continue reading How to create a new EventType

Get label string in different languages

A while ago I had the need to translate labels, I was creating eMail bodys while using SysMailer and wanted to use different languages for different customers.

I found the class SysLabel and tried to use it. But the problem was that this didn´t work. I allways got the string in the language that was set up under Tools/Options.

   print SysLabel::labelId2String2("@SYS54971", "en-us");

I usually have Swedish setup as language when I run Dynamics AX, and this is the result when running previous code.

Aktiveringsdatum

If there are any english readers: “Aktiveringsdatum” is the Swedish translation of “Activation date“.

I traced the code and found out that the label converts to it’s string before it´s sent into the method labelId2String2. Since the input value wasn’t a labelId anymore, the method just returned the exact string that was sent in.

I found a solution to this problem by piecing together the labelname in the call to the method. It seems that the label didn’t convert to it’s string when I did it this way.
Continue reading Get label string in different languages