My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

01 December 2009

Week numbers in Dynamics AX

by Patrik Luca 7 comments

Tag



Introduction: Week numbers in Dynamics AX

This post is about showing the week number in date controls in Dynamics AX. This was by default shown in Axapta 3.0, but disappeared since Dynamics AX 4.0. The second part of this post describes how you can adapt the week number calculation, as there are different numbering systems.

Showing the week number in date controls in Dynamics AX

To show the week number in date controls, adapt the SysDateLookup form by setting the property ShowRowLabels of the control DaysTable to Yes (which was the default in Axapta 3.0 BTW, so for Axapta 3.0 installations, it is shown anyway.).

Changing the numbering system for weeks

According to the ISO week date system, the first week of the  year is the week containing a Thursday. Whereas in some countries it is more common to see the first week of the year as the one containing January, 1st. The latter is how the date control in standard Dynamics AX is working as you can see below.

To change this, adapt the method drawMonth of form SysDateLookup as follows:

//daysTable.setRowLabel(w,num2str(weekOfYear(
// drawingDate+firstDayOfWeek)
// ,2,0,0,0));
daysTable.setRowLabel(w,num2str(wkOfYr(
drawingDate+firstDayOfWeek)
,2,0,0,0));


This will result in following week numbering:





So there is a difference between the function weekOfYear vs wkOfYr in Dynamics AX, which becomes very clear if we create a small job:



static void CalculateWeekOfYear(Args _args) 
{

    ;

    info(strFmt("weekofYear 05.01.2010: %1"
,weekOfYear(str2date("05.01.2010",123))));
    info(strFmt("wkOfYr 05.01.2010: %1"
,wkOfYr(str2date("05.01.2010",123))));

}

 



Output:




Comments 7 comments
Anonymous said...

Thx Patrik!

Marijus said...

Very helpful article, thanks

Anonymous said...

Yes yes yes, very very helpful

Teisius

Jos Litjens said...

Very nice, thanx! There is however a mistake in your solution: ShowRowLabels should be set to Yes, not ShowColLabels... ;)

Patrik Luca said...

Thanks Jos for mentioning: you're absolutely right, you should set ShowRowLabels to Yes: I changed my blog post text.

Anonymous said...

Cool - work great in AX 2009 as well. Thanks.

Anonymous said...

Even in 2022, it helps with AX v3 (still running) !! Thanks a lot for this great tip

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Blog Archive

My Blog List

Followers

Links