Monthly Archives: March 2008

How to clock routines which (should) go faster than 1 sec

From the basic routines in Axapta we only have the TimeNow() function which returns number of seconds since midnight. To measure something more exact than that, we either need to do an API call to getTickCount or to use the setTimeOut() function. This is a small demo on how to implement both such timers.
Continue reading How to clock routines which (should) go faster than 1 sec

Open filtered forms with X++

When using forms in Dynamics AX we usually get access to them by clicking a button that uses a menu item, this along with the args that is sent we get a form that displays the requested information. But if you want to do this using code, how is this done?

You usually see this used in classes such as SalesFormLetter or PurchFormLetter that uses an existing form instead of a creating a temporary one. The user enters the information and the class uses the new information to perform the tasks at hand.
Continue reading Open filtered forms with X++

Jump between InterCompany order lines

This is a basic job that describes how you can jump from one order line to another in the intercompany order structure.

In this example I have created an intercompany order that also has a linked purchase order in the production company to a vendor. This is one way you can use to jump up between the linked order lines.
Continue reading Jump between InterCompany order lines

WorkCalendarSched

When programming Dynamics AX it is very easy to add days to a date. You can take todays date and just add an integer of five to get the date five days from now. But because this is easy to do it doesn’t mean that this always is the right way to go about this date business.

If you look closer at how the dates are calculated on the sales order lines or the purchase order lines in Dynamics AX you see that a class called WorkCalendarSched is used. This is because deliveries are dependant on when the company using Dynamics AX actually can send the order. Not all companies work on weekends.

This is when WorkCalendarSched comes in handy, with this class and the class method “shedDate” you can make sure that the delivery is set to a day when the company actually is going to be able deliver.
Continue reading WorkCalendarSched

strFmt

This is an easy way to use labels and infologs in a bit more dynamic manner. It also makes it easier to do type conversion of for example dates to strings when printing to infologs.

1
2
3
4
5
6
7
8
9
10
11
12
13
static void FO_StrFmt(Args _args)
{
    CustTable   cust    = CustTable::find("4000");
    SalesTable  sales   = SalesTable::find("00697_036");
    ;
 
    info(strFmt("Hello %1!", cust.Name));
 
    info(strFmt("Hello %1, you live in %2!", 
                cust.Name, cust.City));
 
    info(strFmt("%1", sales.DeliveryDate));
}

OutPut:

Hello Light and Design!
Hello Light and Design, you live in Los Angeles!
2008-03-04

Notice that the date is presented in the format that is set up on the clients computer. In this case the Swedish format. The same format that you see in the Sales Table form.

Strange behaviour when calling form

I was building an extended search form for one of our customers. When called from one form everything worked fine, but when called from a second form my grid only contained one record… Exact same parameters, same menu item etc. When looking around I found that when the error occured, I was calling from a form which had same table (InventTable) as one of it’s main Data Sources. This is one of the non-documented features in AX, if same table exists in the Data Sources in both forms, AX tryes to link them together. To break this connection I had to call ClearDynaLinks() on the second form. Like below, in my search form’s init method.

1
2
3
4
5
6
7
8
9
void init() 
{
 
    ....
 
    InventTable_ds.query().dataSourceTable(
                 tablenum(InventTable)).clearDynalinks();
 
}