Archive for the ‘Dynamics AX 4.0’ Category

Intercompany with buf2buf

Wednesday, November 7th, 2007

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:
(more…)

date2int is date2num

Tuesday, November 6th, 2007

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?
(more…)

Basics of changecompany

Tuesday, November 6th, 2007

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.
(more…)

How to create a new EventType

Friday, November 2nd, 2007

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.
(more…)

Get label string in different languages

Thursday, November 1st, 2007

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.
(more…)

Simple progress counter

Thursday, November 1st, 2007

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.
(more…)

YesNoBox

Wednesday, October 31st, 2007

A simple way to let the user deside what is going to happen.

1
2
3
4
5
6
7
   if(box::yesNo("Do you want something to happen?", 
      dialogbutton::Yes) == dialogbutton::Yes)
   {         
 
          somethingHappens = this.callTosSomeReturnMethod();
 
   }