Monthly Archives: November 2007

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