1. If both dates are empty, the record should be selected based on ItemId.
2. If either date is greater than the current date (todate), the record should be selected.
I have implemented this code but it's not working as required:
Query query = new Query();
QueryBuildDataSource qbds;
SysTableLookup sysTableLookUp;
if (TestTable.ItemId)
{
InventBatchExpDate currentDate = DateTimeUtil::date(DateTimeUtil::getSystemDateTime()); // to select current date
date nullDateCheck = mkDate(1, 1, 1900); //will use to compare null dates
qbds = query.addDataSource(tableNum(InventBatch));
qbds.addRange(fieldNum(InventBatch,ItemId)).value(TestTable.ItemId);
qbds.addRange(fieldNum(InventBatch, expDate)).value(strFmt('((%2 > %1 ) || ( %2 == %3 ))', currentDate, fieldStr(InventBatch, expDate),nullDateCheck));
qbds.addRange(fieldNum(InventBatch, PdsVendExpiryDate)).value(strFmt('((%2 > %1) || ( %2 == %3))', currentDate, fieldStr(InventBatch, PdsVendExpiryDate), nullDateCheck));
sysTableLookup = SysTableLookup::newParameters(tableNum(InventBatch), this);
sysTableLookup.addLookupField(fieldNum(InventBatch, InventBatchId));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Major challenge:
1. Null date is passing to qbds as empty (expDate == ) but it should be as (expDate == 01/01/1990 ).
2. How to deal using Query Build AddRange If one date is greater than today's date and other date is not null but less than today's date?
#D365FO | #X++ | #Dynamics365 | #D365Finance | #AXDevelopment | #ERPDevelopment | #MicrosoftDynamics | #AX2012 | #D365Customization | #F&ODevelopment | #D365 | AOTQuery