08 August 2018

how to compare the date field in query | Date query range in AX 2012 | how to add date query range in ax 2012

how to compare the date field in query | Date query range in AX 2012 | how to add date query range in ax 2012
How to set range with Date field with Date value in AX 2012

queryBuildRange.value(strFmt('(ModifiedDate <= %1)', Date2StrXpp(01\01\2000))); // in this example ModifiedDate is query Range field what we are adding. Another example: queryBuildDataSource = query.addDataSource(tablenum(PriceDiscTable)); queryBuildDataSource.addRange(fieldNum(PriceDiscTable,FromDate)).value(strFmt("FromDate<=%1",toDate)); queryBuildDataSource.addRange(fieldNum(PriceDiscTable,ToDate)).value(strFmt("ToDate>=%1",toDate));


Perfect solution is:

public void lookup(FormControl _formControl, str _filterStr)

{

SysTableLookup sysTableLookup;

//Query query = new Query();

//QueryBuildDataSource queryBuildDataSource;

//QueryBuildRange queryBuildRange,queryBuildRangeFrom,queryBuildRangeTo;

//date toDate = today();



PriceDiscTable PriceDiscTable;

QueryRun QueryRun;

Query Query;

QueryBuildDataSource qbds;

QueryBuildRange qbr;



TransDate todaydate;

todaydate = systemDateGet();



super(_formControl, _filterStr);



sysTableLookup = SysTableLookup::newParameters(tablenum(PriceDiscTable), _formControl);



sysTableLookup.addLookupfield(fieldnum(PriceDiscTable, ItemRelation));

sysTableLookup.addLookupfield(fieldnum(PriceDiscTable, relation));

sysTableLookup.addLookupfield(fieldnum(PriceDiscTable, AccountRelation));





Query = new Query();

qbds = Query.addDataSource(tableNum(PriceDiscTable));

qbds.addSortField(fieldNum(PriceDiscTable,todate),SortOrder::Descending);

qbr = SysQuery::findOrCreateRange(qbds,fieldNum(PriceDiscTable,Fromdate));

qbr.value('<='+SysQuery::value(todaydate)); qbr = SysQuery::findOrCreateRange(qbds,fieldNum(PriceDiscTable,todate)); qbr.value( strfmt('((%1 = %2) || (%3 > %4))',fieldStr(PriceDiscTable,ToDate),date2strXPP(datenull()),fieldStr(PriceDiscTable,ToDate),date2StrXPP(todaydate)));



qbr = SysQuery::findOrCreateRange(qbds,fieldNum(PriceDiscTable, AccountRelation));

qbr.value(queryValue(sfcorderguidemaster::find(sfcorderguideitemmaster.Orderguideid).PriceGroup));


qbds.addGroupByField(fieldnum(PriceDiscTable, ItemRelation));

qbds.addGroupByField(fieldnum(PriceDiscTable, ItemCode));

qbds.addGroupByField(fieldnum(PriceDiscTable, AccountRelation));

//add the query to the lookup form

sysTableLookup.parmQuery(query);

// Do the lookup

sysTableLookup.performFormLookup();

}

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...