Thursday, May 20, 2010

Enterprise Portal: Adding an AX Web Control and Resolving the “unable to load content” Error

Following the tutorial on creating a web part page for Enterprise Portal in the book “Microsoft Dynamics AX 2009 Programming: Getting Started” by Erlend Dalen (Great book by the way!) things seemed simple enough from creating a dataset in AX (page 290) to creating the web part in Visual Studio (pages 291-295). Even the first steps of creating the web part page was straight forward (296-299). However, because my development environment was in 64-bit Windows, when it came to modifying my shared web part, to use the web part that I built in Visual Studio, one additional key step was needed. At first I received the following error message:

'unable to load content [webcontrol name]. Please contact your systems administrator'

Finding Out What The Actual Problem Is

In order to get to the bottom of what was actually going on, I learned that I needed to modify my main web.config file which is located at:


to give me a more useful message.

1) First, I needed to modify the following line that begins with:

SafeMode MaxControls=”200” CallStack=”false” …

And change the CallStack property to “true

2) Next, I needed to modify the following line:

customErrors mode=”On” /

And change the mode property to “Off

3) Next, I needed to modify the following line:

compilation batch="false" debug="false"

And change the debug property to "true"

4) I then saved the the web.config file
5) Restarted IIS by executing the IISRESET command in the command prompt
6) Went through the steps of creating the web part page again.
7) I then received a far more useful error, with the first line of the error telling the story:

System.Web.HttpException: The file '/_layouts/ep/[webcontrol name].ascx' does not exist.

The Missing Step

Now knowing that the problem was that my control files didn’t actually exist where SharePoint expected them, I needed to locate the exact path where these files belonged. As it turns out, after searching, the “/_layouts/ep” path is not a physical path on the machine, so I had to find its physical location some other way. How I did this was searching the hard drive for another AX web part that was in the list of webparts that I verified was able to load (so I searched for “ActivitiesListAssociations”). This led me to the physical path of:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\ep

As expected, my custom web control files were not there.

So I copied the .ascx and .ascx.cs files from my project to this path, went through the steps to create the web part page, and web part finally loaded!

Tuesday, May 18, 2010

Setting Default Values on a New Record in a Grid

Today is another newbie quick-tip. Setting default values on a new record in a Grid is a simple task. To do this, you need to override the initValue() method on the Form's Data Source. Let say I have a Table named tblDefault which contains two fields TheDate, which is a UtcDateTime type, and Who, which is a String type. In my example, I want the TheDate field to default to the current date time, and the Who field to default to the User Id of the current user:

public void initValue()

// I’ll use the custom function to get the current date/time from here
tblDefault.TheDate = this.Now();
// AX has a built in function to get the current User Id
tblDefault.Who = curUserId();

Wednesday, May 5, 2010

Debugger Isn’t Working in the clicked() Method

Today I found that something in one of my form button clicked() methods was not doing what I expected it to do. So I put a breakpoint on the particular line of code in the method so that I could execute the process and see exactly what was going on. However, execution was not halting at my breakpoint, and the debugger was never being triggered. After making sure I was attempting to debug the right code, restarting my AX Client, then my machine, and finally the AOS itself, all to no avail; I quickly realized something buggy was going on. A little digging led me here, which acknowledged this as being a known bug in AX. The most basic solution turns out to be simple, and requires the use of the “breakpoint” keyword in the code where you want the breakpoint.

The only problem is that you will want to make sure you remove these breakpoint keywords when you are done!
void clicked()


Tuesday, May 4, 2010

A Now() or GetDate() Method for AX

It should be noted, that after I made this post, it was revealed to me that the DateTimeUtil::utcNow() method accomplishes this goal...

Today I simply have a quick tip. I needed to be able to obtain the current date & time; something similar to the DateTime.Now() function in .NET or the getdate() function in SQL Server; However as far as I can tell, AX provides no quick function for this, so I wrote my own:

public utcdatetime Now()

str tDate;
str tTime;
utcdatetime utc3;


tDate = date2str(systemDateGet(), 321, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4);
tTime = time2Str(TimeNow(), TimeSeparator::Colon, TimeFormat::AMPM);
return str2datetime(tDate + " " + tTime, 321);