The following code is an example of how to build a query range based on a Form Data Source, which displays only "daily" records.
In the example the form-dataSource is named DataSourceName is a date effective table. Depending on a check box only records should be displayed, which that are valid for todays date.
While it is quite a simple task, I want to remind how much easier and more reliable the code is if we use AX built in methods: in particular those two classes:
- SysQuery
- DateEffectivenessCheck
public void applyFilter()
{
queryBuildRange qbr;
qbr = sysQuery::findOrCreateRange(DataSourceName_ds.queryBuildDataSource(), fieldNum(DataSourceName, recId));
if( !ShowExpiredCheckBox.checked())
{
qbr.value(
strfmt(
DateEffectivenessCheck::queryRange(true,false,false),
DataSourceName_ds.queryBuildDataSource().name(), // queryBuildDataSource name
fieldstr(DataSourceName, ValidFrom), // table field from date
fieldstr(DataSourceName, ValidTo), // table field to date
DateEffectivenessHelp::queryDate() // test date (MUST use the queryDate method for correct formatting), alternatively can use also: DateTimeUtil::toStr(DirUtility::getCurrentDateTime())
)
);
}
else
{
qbr.value(SysQuery::valueUnlimited());
}
}
how much more code would you need without using those two classes!!
No comments:
Post a Comment