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:
Thx Patrik!
Very helpful article, thanks
Yes yes yes, very very helpful
Teisius
Very nice, thanx! There is however a mistake in your solution: ShowRowLabels should be set to Yes, not ShowColLabels... ;)
Thanks Jos for mentioning: you're absolutely right, you should set ShowRowLabels to Yes: I changed my blog post text.
Cool - work great in AX 2009 as well. Thanks.
Even in 2022, it helps with AX v3 (still running) !! Thanks a lot for this great tip
Post a Comment