Skip to main content

Posts

Cleaning up your Virtual companies

Often consultants create virtual companies and forget to trough away the old data. This can become an issue when migration to a newer version of dynamics AX gets involved. For example if the CustTable & VendTable become virtual, have the old data no PartyID number and the unique index on this column can’t be enabled. The easiest way for removing these obsolete records is using sql script. I have added an example. Imagine a table collection with CustTable and VendTable. This table Collection is used in Virtual Company DMOV. Company DMO1 and DMO2 uses this virtual company. In case the records in CustTable and VendTable were not deleted for company DMO1 and DMO2, the next SQL script will help you: delete FROM [AX2009_SP1_Dev] . [dbo] . [CustTable] where DATAAREAID in ( 'DMO1' , 'DMO2' ) delete FROM [AX2009_SP1_Dev] . [dbo] . [VendTable] where DATAAREAID in ( 'DMO1' , 'DMO2' ) But what happens if the customer decides not to use...

Reflection with the Dictionary

In X++ it is possible to write code that inspects the structure of other X++ code. This is sometimes called reflection or meta-programming. You may wonder why you’d want to do that. Reflection is a very powerful tool and opens a wide array of possibilities. Without it some things would be very hard or even impossible to implement. Just look at the code behind table browser, the unit testing framework, or the data export and import tools. There are several ways to do reflection in X++. I’m going to show an example using the Dictionary. It involves classes whose names start with Dict and SysDict. The latter are subclasses of their respective Dict-class and can be found in the AOT. The goal Suppose you need to analyze the performance of an existing application. You could set up monitoring but you need an indication where to start. The largest tables in the database, i.e. those with most records, are potential performance bottlenecks. For large tables it is important to have the ...

A quick fix for unbalanced TTS

During development you may encounter one of these. This usually leaves your Ax session in an unusable state that you can’t close properly. However, there’s no need to get out the big guns and kill the process with the Task Manager. Instead, if possible, open the AOT and run this job: static void resetTTS ( Args _args ) { while ( appl. ttsLevel ( ) > 0 ) ttsAbort ; }

Getting a value from a field if you only know the field ID

static void Job4 ( Args _args ) { CustTable custTable; FieldId fieldId; ; fieldId = fieldNum ( CustTable , AccountNum ) ; // This could be passed as a method parameter select custTable; // Get first record print custTable. ( fieldId ) ; // Print account number select custTable where custTable. ( fieldId ) == '1101' ; // Where clause based on field ID print custTable. Name ; pause ; }

Comparing records

Sometimes you need to know what’s the difference between records. I made a simple function to do just that.It takes two records and returns a container with the field IDs and the values from both records. For simplicity I used a flattened container instead of more complicated data structures. Feel free to replace it with nested containers or some kind of collection. I added this to the class Global for easy access. public static container compareRecords ( Common _record1 , Common _record2 ) { SysDictTable dictTable = new SysDictTable ( _record1. TableId ) ; SysDictField dictField; FieldId fieldId , extFieldId; container ret; int i , j; ; if ( _record1. TableId != _record2. TableId ) return conNull ( ) ; for ( i = 1 ; i <= dictTable. fieldCnt ( ) ; ++ i ) { fieldId = dictTable. fieldCnt2Id ( i ) ; dictField = new SysDictField ( _record1. tableId , fieldId ) ; i...

X++ Code Snippet: Copying records

static void CopyFields(Common _from, Common _to) {      DictTable           t;     DictField           f;     int                  i;      fieldId             id;     FieldName           fieldname;      ;     t = new DictTable(_to.TableId);     if (t)     {         for (i= 1 ; i<=t.fieldCnt(); i++)         {             id = t.fieldCnt2Id(i);             f  = new D...

Managing Client Versions

How do you know if you have updated all of your client machines to the correct and current AX version? For a lot of companies that have distributed clients, managing the client software can be somewhat of a headache for the IT staff. As the roll out of new kernel builds are released, it is important to make sure the client applications are updated as well. It is especially difficult if the client applications are located on mobile machine or computers that may not be inaccessible locations due to a variety of business requirements. The following code suggestion can be put into the AOD to help prevent client side applications from logging into the production system when it has not been updated to the correct kernel version. When our Premier Field Engineer team performs a Health Check , we will check the client executable to make sure they are on the same kernel version as the AOS. This helps improve the AX environments stability. 1) Within the AOT, create a new class a. In...