Tuesday 27 September 2011

Dynamics AX batch job relative day parameter

When we add batch job into batch list, it is quite often we need to enter a date into the query. Sometimes we wanted to add them once and works forever, we doesn't want to manually edit the query value every now and then.

Eg. You want to add a report into batch job based on current month, instead of putting a fixed value range of 01/09/2011..30/09/2011, you can put (monthRange(0,0)) or (monthRange()).

All example below will assume today's date is 30/06/2011.
Query value Description
(day(relativeDays))client server public static str day([int relativeDays])

Relative days to today's date. Default to 0 when the 'relativeDays' optional parameter is ignored. Can be offset + or -.

Eg.
(day(-1)) will gives you 29/06/2011
(day(0)) will gives you 30/06/2011
(day(1)) will gives you 01/07/2011
(dayRange(relativeDaysFrom, relativeDaysTo))client server public static str dayRange([int relativeDaysFrom, int relativeDaysTo])

Relative day range from and to given today's date.
To get past 1 week + next 1 week date, you can use (-7, 7).

Eg.
(dayRange(0,0)) gives you 30/06/2011 to 30/06/2011
(dayRange(-2,2)) gives you 28/06/2011 to 02/07/2011
(dayRange(0,2)) gives you 30/06/2011 to 02/07/2011
(dayRange(-2,0)) gives you 28/06/2011 to 30/06/2011
(greaterThanDate())client server public static str greaterThanDate([int relativeDays])

Similar to (day()), but give the date of after the offset.

Eg.
(greaterThanDate(0)) gives you "> 30/06/2011"
(greaterThanDate(2)) gives you "> 02/07/2011"
(greaterThanDate(-2)) gives you "> 28/06/2011"
(lessThanDate())client server public static str lessThanDate([int relativeDays])

Similar to (greaterThanDate()), but the other way round.

Eg.
(lessThanDate(0)) gives you "< 30/06/2011"
(lessThanDate(2)) gives you "< 02/07/2011"
(lessThanDate(-2)) gives you "< 28/06/2011"
(monthRange(relativeMonthsFrom, relativeMonthsTo))client server public static str monthRange([int relativeMonthsFrom, int relativeMonthsTo])

Similar to (dayRange()), instead of days, it gives months.
(yearRange(relativeYearsFrom, relativeYearsTo))client server public static str yearRange([int relativeYearsFrom, int relativeYearsTo])

Similar to (dayRange()), instead of days, it gives years.

These methods is coming from the class "SysQueryRangeUtil".

*NOTE: It needs the bracket around the method name.
Eg.
- Correct: (day(0))
- Incorrect: day(0)

More details at: http://msdn.microsoft.com/en-us/library/cc618616(v=AX.50).aspx


Sample screenshot
*All screenshot taken at date 30/06/2011.

(day(0))

(day(1))

 (day(-1))

*This is the tips from my colleague - Matt.

No comments:

Post a Comment