November 12, 2019

Creating and testing a strongly typed Stack class in X++

Filed under: 365 for Finance and Operations — Joe Brewer @ 12:47 pm

For my latest project in X++ I needed to use a Stack. .NET does already provide a Stack class however MS recommends using the Generics version as it is faster because it is typed. See Non-generic collections shouldn’t be used on GitHub. I had initially tried creating a Stack class using a container, but it was painfully slow – it took several minutes to push and pop 100,000 elements onto and off of the stack.

Here is my implementation:

class Stack extends List
    private Types dataType;

    public void push(anytype _value)
        // double check that we have received a variable of the correct type
        if (typeOf(_value) != dataType)
            throw error("Incorrect data type");


    public void new(Types _type)
        dataType = _type;


    public anytype pop()
        ListIterator iterator;
        anytype topValue;

        // double check that there is an element on the stack
        if (!this.elements())
            return null;

        iterator = new ListIterator(this);

        // position the iterator to the top

        // retreive the value
        topValue = iterator.value();

        // remove the element from the stack

        // return the value
        return topValue;

Here is a job to demonstrate how to use the class and to test the speed of pushing and popping 100,000 elements on to and off of the stack:

class StackTest
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        System.Random random;
        System.Diagnostics.Stopwatch stopwatch;
        System.TimeSpan timeSpan;
        Stack numberStack;
        str elapsedTime;

        random = new System.Random();
        numberStack = new GWStack(Types::Integer);
        stopwatch = new System.Diagnostics.Stopwatch();


        // push 100,000 random numbers onto the stack
        for (int i = 0 ; i <= 100000 ; i++)
            numberStack.push(random.Next(1, 1000));

        // pop everything off of the stack one by one
        for (int i = 0 ; i <= 100000 ; i++)

        timeSpan = stopwatch.Elapsed;

        elapsedTime = System.String::Format("{0:00}:{1:00}:{2:00}.{3:0000}",
            timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds,

        info(strFmt("elapsed time for list based stack: %1", elapsedTime));


The results show that pushing and popping 100,000 elements is well under 1 second.

Let me know if you use it or if you found this helpful.

October 4, 2019

Too many forms – Dynamics AX 2012 error

Filed under: Dynamics AX 2012 — Joe Brewer @ 4:33 pm

Recently I had an issue with a customer who is using Microsoft Dynamics AX 2012 where users were experiencing the dreaded “too many forms” error. If you have experienced this issue you will know that the only way to stop it is to restart the AX client. Restarting the client, however only gets rid of the error for a short period of time.

Searching the net for information doesn’t give much information on what can cause the error. One post from the awesome art of creation blog has some good information though. Especially for explaining how to monitor the user objects using windows task manager.

The “too many forms” error was unfortunately not caused by a missing super() call in a form, however the customer was happy to monitor the task manager whilst testing. I was pretty surprised at this as the people testing thought that this was incredibly tedious. However, the testers managed to narrow down where the problematic code was, and I was able to track down and sort the issue.


The issue was with third party code, as you would probably expect

The problem was essentially that a function was written that returned an object, but was called with out assigning the value to a variable. The main method of the SalesFormLetter class had been overridden to return the local salesFormLetter variable. The users only had to use this class a handful of times before getting the error and having to restart the client.

If you are getting this error, I would recommend getting your testers to monitor the task manager whilst testing. It may annoy them as it significantly slows down their testing, but will make it easier to narrow down the code that is causing it. When you have the form, class or whatever seems to have the issue, check out any customisations in that area.

July 7, 2012

Updates for the wordpress affiliate link cloaker plugin

Filed under: PHP and MySQL,Wordpress — Joe Brewer @ 6:02 pm

It’s been nearly a year since my last post, and many months since the plugin last had any updates. This post outlines the new features in version 1.00.03:

Removing data from the redirect log

The way that the plugin works out how many redirects there are for each address is by logging each redirect and counting the redirects on the link and address pages. One of the things that I didnt account for in the previous version was how to delete or reset this data. Now, when you uncheck the option “count redirects” on the link page and save the options, the entries from the log are removed. Re enabling this option will effectively reset the counter.

Case sensitive keyword/phrase searching

This is a feature that had been requested a little while ago. It enables keyword/phrase searching to be set to case insensitive – this means that the keyword “television” will find and replace “Television” (and other combinations of upper/lower case) in blog posts.

Redirects graph

Under the “count redirects” option on the links page there is now an option to show a traffic graph. Once the check box has been checked and saved, the graph will show at the bottom of the page. This shows the redirects for the current month.

July 11, 2011

Affiliate link cloaker WordPress plugin

Filed under: Internet,Uncategorized,Wordpress — Joe Brewer @ 4:50 pm

Affiliate link cloaker is a free WordPress plugin that can geo target cloaked affiliate links. This plugin has the capability to generate a link like and have visitors from the USA click on the link and get sent to, visitors from the UK sent to and so on.

In addition to this, these cloaked links can be automatically inserted into content. Keywords or phrases can be set to be changed to nofollowed links that open in a new window so that visitors are not taken away from your website.

May 22, 2011

Region detect wordpress plugin

Filed under: PHP and MySQL,Wordpress — Joe Brewer @ 2:57 pm

Region detect is a plugin for WordPress that detects the country that the current visitor is browsing from. It can display the country to the user; something like:

Hello visitor from %%COUNTRYNAME%%

This is done by using the codes %%COUNTRYCOD E%% and %%COUNTRYNAM E%% in your posts (take out the spaces).

The plugin makes the two character ISO 3166-1 country code and country name available to other plugins – just declare the global variables $rdISO3166_1 and $rdCountryName.


« Newer PostsOlder Posts »

Powered by WordPress