Saturday, June 11, 2011

Creating Range on CreatedDateTime in AX2012

Placing a range on field CreatedDateTime on any table/form is little tricky now unlike the previous versions. We have the default fields CreatedDateTime and CreatedBy in all the tables and we want to have a filter on the CreatedDateTime field on a new form as shown below:

Following steps are required for placing the range on CreatedDateTime.

Step 1: Declare two variables in ClassDeclaration:

utcDateTime fromDateSelection, toDateSelection;

Step 2: Create the range on the field and intialize the default values for variables defined
above in the Form >> Datasource >> init() after super():

qbrCreatedDate = this.query().dataSourceTable(TableNum(xyzTable)).addRange(FieldNum(xyzTable, createdDateTime));fromDateSelection = datetobeginUtcDateTime(dateNull(), DateTimeUtil::getUserPreferredTimeZone());
toDateSelection = datetoendUtcDateTime(dateMax(), DateTimeUtil::getUserPreferredTimeZone());

Step 3:  Write the below code before super() in executeQuery() method:

qbrCreatedDate.value(queryRange(fromDateSelection, toDateSelection));

Step 4: On fromDateTime Control >> modified() write the below code:

fromDateSelection = datetobeginUtcDateTime(DateTimeUtil::date(FromDateTime.dateTimeValue()),DateTimeUtil::getUserPreferredTimeZone());

Step 5: On toDateTime Control >> modified() write the below code:

toDateSelection = datetoendUtcDateTime(DateTimeUtil::date(ToDateTime.dateTimeValue()),DateTimeUtil::getUserPreferredTimeZone());

Step 6: Also, make sure to change the DisplayOption property of the utcDateTime control to 'Date' so that it displays only date as shown below:


This would filter the records on the form basis the date range provided.

No comments:

Post a Comment