All posts by Erik Paulsson

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

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

Simple progress counter

This functionality uses the class SysOperationProgress.

We start by declaring the necessary variables:

1
2
3
4
5
6
    // ProgressCounter
    #avifiles
    SysOperationProgress                oProgress;
    int                                  nTotal;
    #define.TITLE("Processing...")
    ;

nTotal needs to be set to a number that reflects the process that is going to take place. If we know that we will go through a loop 2000 times, then we set nTotal to the value 2000.
Continue reading Simple progress counter