Set query range for Two Date ( FromDate To Date) field in a table in Ax 2012

 

static void DateRangeTest(Args _args)
{
DateRangeTest drt;

Query query=new Query();
QueryRun qrun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
date d=today();
qbds=query.addDataSource(tableNum(DateRangeTest));

qbr=qbds.addRange(fieldNum(DateRangeTest,dataAreaId));
//Method 1
//qbr.value(strfmt(‘(%1<=%2)&& (%3>=%4)’,fieldstr(DateRangeTest,FromDate),Date2StrXpp(d),fieldstr(DateRangeTest,ToDate),Date2StrXpp(d)));
//Method 2
qbr.value(strfmt(‘(FromDate<=%1)&& (ToDate>=%2)’,Date2StrXpp(d),Date2StrXpp(d)));

qrun=new QueryRun(query);
info(qrun.query().dataSourceNo(1).toString());
while(qrun.next())
{
drt=qrun.get(tableNum(DateRangeTest));
info(drt.Name);
}
info(drt.getSQLStatement());
}

Advertisements

4 comments on “Set query range for Two Date ( FromDate To Date) field in a table in Ax 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s