Dynamics AX 2009 – Override lookup field in dialog.

Since I’ve been working with AX for over 4 years now, I think it’s time I start writing about some of the useful tricks I’ve learnt.

I’ll start wit a useful thing I learnt today. I’s fairly straight forward to override the lookup method for the field a form. But it gets more difficult when we are dealing with a dialog box, since the dialog fields are created at run time.

Step 1, create a new class, extending from RunBase

class MyDialog extends RunBase
    Dialog dlg;
    DialogField dlgEmpl, dlgLocation, dlgPrintScreen;

Override the dialogPostRun and dialog methods. (You will also need to implement the pack and unpack methods).

protected Object dialog
     (DialogRunbase dialog, boolean forceOnClient)
    dlg = super(dialog, forceOnClient);

        = dlg.addField(typeid(EmplId), "Person");
        = dlg.addField(typeid(WMSLocationId), "Location");
        = dlg.addField(typeId(NoYes), "Print to screen");    
    return dlg;

public void dialogPostRun(DialogRunbase dialog)
public container pack()
   return conNull();
public boolean unpack(container packedClass)
    return true;

The important bit here are the controlMethodOverload methods. It allows this class to be used instead to control the lookups.

Now when dialog fields get created at runtime, they get a system named. This can be view in AX by right clicking on the field and selecting setup (in AX2009).

THe names will be along the liens of ‘fld_1_1’ , ‘fld_2_1’ etc

To create the lookup method override (or any other method override), create a new method in your class with the field system name, and the method name, like this;


void Fld2_1_lookup()
    WMSOrderTrans wmsOrderTrans;
    FormStringControl control = dlg.formRun().controlCallingMethod();
   SysTableLookup sysTableLookup =  SysTableLookup::newParameters(tablenum(WMSLocation),control);
   Query                   query = new Query();
   QueryBuildDataSource    queryBuildDataSource;
   QueryBuildRange         queryBuildRange;
   queryBuildDataSource = query.addDataSource(TableNum(WMSLocation));
   queryBuildRange = queryBuildDataSource.addRange(FieldNum(WMSLocation, inventLocationId));
  select firstonly wmsOrderTrans where wmsOrderTrans.routeId == wmsPickingRoute.pickingRouteID;
   queryBuildRange.value( wmsOrderTrans.inventDim().InventLocationId);
   sysTableLookup.addLookupfield(fieldnum(WMSLocation, wMSLocationId));
   sysTableLookup.addLookupfield(fieldnum(WMSLocation, inventLocationId));



Posted in Dynamics AX | Tagged , | Leave a comment

Global Game Jam 2011

The global game jam has come to an end. We were able to finish a pretty playable game.
It’s called Noah More Heros, and stars a Noah like old man called Noah. The world is flooding, and its up to Noah to save the day, or just himself.

Posted in Game Development | Leave a comment

Kiwi’s Tale on WP7

This week i’m presenting at the Auckland games development meetup. I’m going to show what i’ve done getting Kiwi’s Tale running on the Windows Phone 7 platform.

WP7 supports two environments,  Silverlight, and XNA. Silverlight is event driven and is suited to business applications, where as XNA runs a game loop and is suited for fast 2d and 3d games.

However there’s nothing stopping you from making a game in silverlight.


Kiwi's Tale running in the Emulator

Erik did most of the work on building an XNA version of Kiwi’s Tale, it was very easy to convert it from a windows to a wp7 project.

The hard part is the controls, XNA has built in functions to recognize gestures like flicking your finger fast or just moving it slowly.  But it still takes a lot of tweaking to get it feeling right, and i’m still far away from that point.

There’s a short video of it here running in the emulator

Kiwi’s Tale on WP7

The second project i’m working on is based on Conway’s Game of Life

Life is a cellular automation created by the mathematician John Conway. It’s essentially a large 2d world with a simple set of rules which determines whether a cell should be alive, or dead.

My idea is to make it into a game, where the player has to ‘fight’ these lifeforms, before getting consumed by them.

Game of Life – Windows Phone 7

This is running in Silverlight, which I like because I have access to all the silverlight controls like textboxes, buttons etc.

However I’ve also implemented a game loop which calculates each step of the game and draws the grid. I’m not sure what performance using silverlight will have until I get hold of an actual device.

Posted in Game Development | Tagged , , , , | Leave a comment

Kiwi’s tale

I started work on a level editor for the XNA version of Kiwi’s Tale, which Erik has been working on building an engine.

I’m using Silverlight to build the engine, which make it easy when working with a Tile based game, It’s currently located here

I will update this page as I make improvements to the editor.

This is sample level in xaml, you may have to select ‘View Source’ to see it

The tile set can be a png image of tiles


If you save a copy of the level xml file and the Tileset, you can upload them using the editor and view the first level.

Level Xml Format

<MapData cols="126" rows="34" cellwidth="32" cellheight="32">
<Layer name="layer0" set="tileset">
<tile id="38" x="0" y="0" />
<tile id="8" x="114" y="30" />
<!-- Entry for each Tile -->
<!-- A level can have multiple levels-->
<BlockInfo blockID="1" userdata="1" userenv="0" collisiondata="0" />
<BlockInfo blockID="93" userdata="0" userenv="0" collisiondata="15" />
<!--Tiles can be assigned data which can be used in game -->

Posted in Game Development | Tagged , , | Leave a comment


I’ve recently just installed wordpress, which is an improvement to what I was previously using. And wordpress is much more suited to what I want to use the site for, which is mainly a blog and a few other pages.

I’ve transfered (copy-pasted) all my content over, however the dates for my previous blog posts are all incorrect.

At the moment i’m quite busy with work, working on Silverlight and web services. But in my spare time i’ve been looking into the Windows Phone 7 platform, hopefully I can make some games for it by the time it’s released later this year.

Posted in Game Development | Tagged , , | Leave a comment

Linq Querying with Grouping and Sum

I’m by no means an expert with SQL, to be honest I try to avoid it at all costs, however I have enough knowledge of it to get by, able to throw a query together into order to get the data I want.

C# implementation of data querying is great, however by no means simpler, in a lot of cases more complicated.

Recently I had a situation where I was required to to a selection from an SQL server database which group together distinct lines, as well as sums the values in a column. This was fairly straight forwards in SQL.

select distinct PeriodName, Con, Cat, Std, TaskSts, sum(Cnt) as TaskCount
from ProgressCount where PeriodName = 'JUL10'
group by PeriodName, Con, Cat, Std, TaskSts

However, I then had to do the same query in Linq, which I had no idea how to do it. After a bit of research I figured it out.

from r in cpx.ProgressCount
            where r.PeriodName.ToLower() == Month.ToLower()
            group r by new { r.PeriodName, r.Con, r.Cat, r.TaskSts} into g
            select new RScount()
                PeriodName = g.Key.PeriodName,
                Con = g.Key.Con,
                Cat = g.Key.Cat,
                TaskSTs = g.Key.TaskSts,
                TaskCount = g.Sum(r => r.Cnt).Value                                    

It’s pretty crazy, using an anonymous type for the grouping (which had to go before the select statement, as everything in linq is done in the opposite order from SQL), and my own type for the selection object, plus a Lambda expression to sum up the values.

I found a useful program, called ‘Linqpad’ http://www.linqpad.net/ which is like SQL Service Management Studio, except you can use C# linq queries against a database, which is great for testing whether your Linq query returns the correct data or not.

Posted in C# | Tagged , , | Leave a comment

Gameplay and Graphics

Recently i’ve been playing a game called Dwarf Fortress. When I first saw the game, I wasn’t too impressed. However I decided to give it a go. I downloaded a tileset which changed the ASCII characters to sprites which showed a bit more visual information.

However I love the game now, the gameplay is really complex and fun. And it’s great that we still have games which concentrate on gameplay rather then graphics.

Anyway i’m going to take Warspace down the same kind of path, for a while i’ve been stuck on what to do with spaceships. I want to have a large range of ships to chose from, however I lack the skill to draw them. So my idea is just to have a symbol, or icon representing a ship or fleet of ships, where the icons could be simple outlines like the graphics in Defcon.

For each ship, a player will be able to chose what kind of engine, weapons, shields it has. The player will also be able to save his/her own template for ships built at the players planets.

Posted in Game Development | Tagged , , | Leave a comment


I’ve always liked playing Chess, however i’ve never been very good, I only think a few moves ahead, if that. Usually I go on instinct. Computers go the opposite way, calculating which moves would be the best by looking ahead and seeing which one would result in a win.

The game of Chess has been made into computer programs countless times already. However I wanted to try it myself, mainly because if I want to make TimeChess, I’m going to need a good understanding of how it works. The WPF Grid element was excellent at making the chess board. The difficult part was creating the game logic which would allow the pieces to make their moves. The piece that proved most difficult was the ‘Pawn’, it’s the only one which requires the game logic to know what team it’s on, as the direction it moves depends on the team it’s on. Also it has a number of special moves like it capture and it’s starting move. The rest of the pieces (apart from Castling) are pretty simple to implement, even the knight moves.

case Piece.Knight :
                    if (
                        (thisX == lastX + 1 || thisX == lastX - 1)
                        (thisY == lastY + 2 || thisY == lastY - 2)
                        (thisX == lastX + 2 || thisX == lastX - 2)
                        (thisY == lastY + 1 || thisY == lastY - 1)
                        moveVaild = true;
Posted in Game Development | Tagged | Leave a comment

Data Binding

With my Warspace game, i’ve separated the code into two categories. First there are the xaml files, and the c# code files for those xaml files. They are responsible for displaying information on the screen to the user. Then I have all the game objects and game logic files, which keep track of all the planets, the buildings and resources on the planets.

Objects which require it have an update method. This update method takes care of calculating (every second) things like how many resources are being produced on a planet, or how much power is being used by the buildings on the planet. One thing I had to have is the display be updating with the information in the game objects in real time. So for example, if a building has finished being built, the display would show the change. Previously I had a few update method for the display, that the Game Objects could call (via a Handler) to tell the display to update.

However this was quite tricky, it was a lot of work as I had to write update methods for everything they could be changed, and I could see that wasn’t going to work. Fortunately WPF has data binding, which I didn’t really understand at the start. I searched lots of websites and looked at examples, but a friend explained to me what I wanted and I got it working.

dataBindings.Add("Power", new Binding());
dataBindings["Power"].Source = planet; 
dataBindings["Power"].Path = new PropertyPath("Power"); 
txtPower.SetBinding(TextBlock.TextProperty, dataBindings["Power"]);

This is a bit of the code for the Planet Manager window, showing the binding for the Power text, which is how much power is being generated on the planet. Because I had to have lots of different bindings for different elements on the display, I made a Dictionary to store them. This allowed me to simply make a new binding whenever I need it, and refer to it by using a string (in this case “Power”) The source of the binding is a ‘planet’ object, and the Path refers to which property of the ‘planet’ this binding is for.

In order for a game object to be used this way, it need to implement the interface ‘INotifyPropertyChanged’ like so;

public class Planet : IUpdatable, INotifyPropertyChanged 
  public event PropertyChangedEventHandler PropertyChanged;
  void OnPropertyChanged(string prop)
  if (PropertyChanged != null)
  PropertyChanged(this, new PropertyChangedEventArgs(prop)); 

Now then a Property can be defined like this;

public int Power 
 get { return power; } 
 power = value ;

Each time the ‘Power’ Property is set, it calls the ‘OnPropertyChanged’ method, passing a string saying which Property has been changed. The Binding for the Power Textblock in the display is notified of the change and then the Textblock shows the new value.


All the elements here, like the building percentages, building level and power using bindings to reflect the values in the planet object.

Posted in Game Development | Tagged , | Leave a comment


Warspace is coming along nicely, wpf makes it really easy to get something up and running quickly. It still looks a bit ugly, my UI design has never been my strong point. I’m using xml files for my game data, it’s easy to read into the application by using Linq, which allows me to use a kind of SQL command on the xml as it were a database. I’ve done xml files for planet types and trade resources, and now i’m making one for buildings. I intend to have a lot of buildings, to give the player a choice, different types of mining facilities, power producing plants. Some buildings will be restricted to certain planets, while some planets will be unable to produce certain resources.

Players will be required to trade resources and set up trade routes to sustain a planet. I’m not going to draw pictures of each building, it’s beyond my ability to make a decent looking picture. Hopefully someone else will volunteer to help out with the artwork. Hear are the features I will be working on in the near future;

  • Colonizing
  • Building
  • Setting up Automatic trade routes (this will involve buying a trade ship, and giving it orders to transfer resources between two planets).
  • I would also like to have more ships to chose from, where the player could buy better ships etc, and maybe also the ability to have multiple ships in a fleet. However this will depend on whether I can find someone to help with the ship artwork.
Posted in Game Development | Tagged , , | Leave a comment