Complex or Advance Query Ranges - D365
Complex or Advance Query Ranges using null, enum, expressions in D365
I came across the requirement to add custom ranges on
query which cannot be handled by using the simple query add range method. So, I
used query expressions to add range on query according to the requirement.
Below are some ways to use advance or complex query ranges.
We can pass values in query ranges by using strfmt
so that %1 gets the value of X and %2 gets the value of Y.
To get complete compile-time stability, use intrinsic functions to
return the correct field names, as shown in the following code example.
strFmt('((%1 ==
%2) || (%3 == %4))',
fieldStr(MyTable, A), x,
fieldStr(MyTable, B), y)
Comparing with null:
We can use strfmt (%1 = = ‘ ‘) but instead it is
better to use empty string function of SYSQUERY ;
qbrDate.value(strFmt('(%1
!= %2)’ ),
fieldStr(InventTrans, DateInvent),
SysQuery::valueEmptyString());
Comparing with somevalue:
We there are many functions of SYSQUERY, as we already saw valueEmptyString(), other is value(), we can specify any value in it. Similarly valueLike, ValueNot etc
qbr.value(SysQuery::value(NoYes::Yes));
Using as-on-date:
It gets the date that user input and then convert that date to string using
str inventDate = date2StrXpp(date);
qbrDate.value(strFmt('(%1 != %2)’ ),fieldStr(InventTrans, DATEPHYSICAL),inventDate));
Using multiple enum values
enum2str
qbr.value(strfmt("%1, %2",enum2str(PurchStatus::Backorder), enum2str(PurchStatus::Received)));
any2 int is also a good option for
extracting enum values in SQL as it brings the enum values in numbers
example :
qbrStatus.value(strFmt('((%1 != %3) || (%1 != %5) || (%1 != %6) || (%2 != %4))',
fieldStr(InventTrans, StatusIssue),
fieldStr(InventTrans, StatusReceipt),
any2int(StatusIssue::OnOrder),
any2int(StatusReceipt::Registered),
any2int(StatusReceipt::Ordered),
any2int(StatusReceipt::QuotationReceipt)
));
Using expressions for customizing ranges on query:
QueryBuildDataSource qbdsInvent;
qbrDate = qbdsInvent.addRange(fieldNum(InventTrans, RecId));
qbrDate.value(strFmt('(((%2 != %1) && (%2 <= %4)) || ((%2 == %1) && (%3 != %1) && (%3 <= %4)))',
SysQuery::valueEmptyString(),
fieldStr(InventTrans, DateInvent),
fieldStr(InventTrans, DATEPHYSICAL),
inventDate));
Comments
Post a Comment