Filtering records according to the date range

Hi All,

I have designed a form similar to form design which is in ‘Ledger\Inquiries\Tax\India posted tax\Service tax\Service tax’. - form name “ServiceTaxInquiry_IN” .
The fields for the column of the form (i.e)The fields in the ’ Available List’ are taken form another table which is created by me.According tto he fields selected and the date range given the records are fetched form the "LedgerTrans table"

In this newly created form , the method ‘createQuery ‘ which used to filter the recs form the LedgerTrans table ,according to the ‘From date’ and ‘To date’(both dates should be specified mandatorily).
public QueryRun createQuery(FromDate _fromDate, ToDate _toDate)
{
Query queryLoc = new Query();
str Qstr;
queryBuildDataSource qbds;
LedgerTrans LedgerTrans;
;
if (_fromDate && _toDate)
{
// queryLoc.addDataSource(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans, TransDate)).value(strfmt(’"%1"…"%2"’,_fromDate, _toDate));
queryLoc.addDataSource(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans, TransDate)).value(queryRange(_fromDate,_toDate));
}
else
{
queryLoc.addDataSource(tablenum(LedgerTrans));
}
queryRun = new QueryRun(queryLoc);
// Actual Query Executed
info(strfmt(‘Actual Query Executed’));
qbds = queryLoc.addDataSource(tableNum(LedgerTrans));
info(qbds.toString());
// Actual Query Executed
return queryRun;
}
In this method the statement
queryLoc.addDataSource(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans, TransDate)).value(queryRange(_fromDate,_toDate));
returns nothing, because when I decoded the query which is executed. the query passed is “ SELECT * FROM LEDGERTRANS”

Please given me clue as where i am making mistake.

Regards,

Rajee.

The problem is not in the range. You actually create one datasource, add a range, then create a second datasource (without ranges) and call toString() on it. No surprise that the second DS has no ranges.

Hi Martin,

If i’m executing the same code with the ranges i.e without the “else” condition,i’m getting the same output in the query object.

-Rajee

Yes, the else part has nothing to do with what I wrote.

You create one datasource - with ranges - here:

queryLoc.addDataSource(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans,
TransDate)).value(queryRange(_fromDate,_toDate));

but then, you create and use a completely new datasource:

qbds = queryLoc.addDataSource(tableNum(LedgerTrans));
info(qbds.toString());

Hi I have created date filter but when i apply date filter a new record is being created also any idea how to sort this out!!!

Would you mind replacing a few exclamation marks with more information?