How to catch special keystrokes and use them as shortcuts

Rightclick on a form and go down tracking a specific field or other data, is a tedious work if you do it dozens of times per day.

We wanted to catch the key combination ctrl+Z (since it is rarelly used when running axapta), so we could use it to display common data about a form, field or other info. This is a code example we nowdays always install in all new test and development environments (not production, since it would give normal users unwanted access).
Continue reading How to catch special keystrokes and use them as shortcuts

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();
 
}

Misc. charges bug

I noticed a bug in the routine for printing out misc. charges on the SalesInvoice_SE document. The problem is that the label that are printed is always “Amount currency”, and the routine doesn’t calculate the amount correctly when the category is set to Pcs or Percent. I Haven’t tested if the SalesInvoice document has the same problem, but the markupSpec method seams to have the same errors so I think it shares the same problems.
Continue reading Misc. charges bug

WP-Syntax

When using WordPress to publish code we take advantage of the functionality of a generic Syntax Highlighter created by GeSHi. To use this in WordPress you’ll need a plugin called WP-Syntax.

Example:

1
2
3
4
5
6
7
8
  static void FO_HelloWorld(Args _args)
  {
      str     HelloWorld = "Hello World!";
      ;
 
      print HelloWorld;
      pause;
  }

My advice to anyone that thinks about installing this plugin is to read about it and it’s functionality. The link to the plugin contains good information that descibes how to edit the look of the code display using CSS.

The magic of InventDim “AllBlank”

Using the PriceDisc class in Dynamics AX is not always the easiest thing in the world. If you start out with a sales line or a purchase line you got methods that helps you get prices from the trade agreement, but if all the info you have is the ItemId and VendAccount it gets a bit tricky.

My thinking was that I should be able to use the PriceDisc class just as the InventOnhand class. You put in basic info, and the more data you enter into the class the more precise the result gets. But the hurdle I had trouble getting over was that the class PriceDisc requires a record from table InventDim, something that you only get if you start out with a sales line or a purchase line.
Continue reading The magic of InventDim “AllBlank”