Hello,
I'm trying to rewrite the following SQL code to dynamic X++ query:
while select BOMId from bomVersion group by routeOpr.IsTechnReasonable_ICL,bom.ItemId,ecoResProduct.RecId where bomVersion.ItemId==itemIdProduction && bomVersion.Active == NoYes::Yes && bomVersion.FromQty == #bomVersionFromQty && ( (bomVersion.FromDate==dateNull() && bomVersion.ToDate == dateNull())|| (bomVersion.FromDate<= systemDateGet() && bomVersion.ToDate >= systemDateGet())|| (bomVersion.FromDate<= systemDateGet() && bomVersion.ToDate == dateNull()) )
I write the following:
static void Job74(Args _args) { Query query; Queryrun qr; QueryBuildDataSource qbdsBomVersion; BOMVersion bomVersion; query = new Query(); qbdsBomVersion = query.addDataSource(tableNum(BOMVersion)); qbdsBomVersion.addRange(fieldNum(BOMVersion,ItemId)).value(queryValue("7075")); qbdsBomVersion.addRange(fieldNum(BOMVersion,Active)).value(queryvalue(SysQuery::value(NoYes::Yes)));
qbdsBomVersion.addRange(fieldNum(BOMVersion,FromQty)).value(queryValue("1")); qr = new QueryRun(query); info(qr.query().dataSourceNo(1).toString()); }
I can't understand how to write this part:
(bomVersion.FromDate==dateNull() && bomVersion.ToDate == dateNull())|| (bomVersion.FromDate<= systemDateGet() && bomVersion.ToDate >= systemDateGet())|| (bomVersion.FromDate<= systemDateGet() && bomVersion.ToDate == dateNull())
Seems like here are two ranges. Tried to use something like this:
qbdsBomVersion.addRange(fieldNum(BomVersion,FromDate)).value(strfmt("((%1.%2 == %4) && (%1.%3 == %4)) || ((%1.%2 <= %5) && (%1.%3 >= %5)) || ((%1.%2 <= %5) && (%1.%3 == %4))", qbdsBomVersion.name(),fieldstr(BOMVersion,FromDate),fieldStr(BOMVersion,ToDate),dateNull(),systemDateGet()));
But with no success. Could you please assist with this?
Thank you.
*This post is locked for comments