Saturday, 25 April 2015

AX2012 R3 : Scheduling dates using X++

Hi Friends,
When required to calculate a future/past dates using X++  based on the working times defined in the working calendar in AX, workcalendarsched class can be used to take off the pain.
The below job shows how we can use the schedDate function and get the result, for simplicity I have passed the calendar name defined in my system as a string:

TransDate       reqDate = systemdateget(), newReqDate;
workCalendarSched   workCalendarSched = new workCalendarSched();
newReqDate = workCalendarSched.schedDate(SchedDirection::Forward,reqDate,5,false,'STANDARD');

Another useful method in this class is isdateopen which can be used to check if a particular date is open in the calendar. The good thing about this class is that it uses SysGlobalObjectCache to store and retrieve the values. It improves the performance when running long and complex calculations.

Notice in the below method, if the key exists in cache then the value is returned from there itself else the cache is updated.

The below method of WorkCalendarSched class initialises the variables from global cache.

The global cache scope is stored on the combination of Class + current partition and current company as highlighted below:

This class is also a good example to understand how to use SysGlobalObjectCache.
Thanks for reading the blog. Keep sharing.

No comments:

Post a Comment