I'm trying to get a QueryRangeFunction to return the valid string for a vendbankAccount that has not expired yet, which means
ExpiryDate = dateMin() OR ExpiryDate > today()
The existing QueryRange functions don't seem to be able to do that, but are valid examples for trying to write my own function:
[QueryRangeFunction]
public static str BankAccountNotExpiredYet()
{
return strFmt("(( %1.%2 = \"%3\") || (%1.%2 > \"%4\"))",
TableStr(VendBankAccount),
fieldStr(VendBankAccount, ExpiryDate),
DateTimeUtil::minValue(),
DateTimeUtil::utcNow());
}
This method returns
(( VendBankAccount.ExpiryDate = "") || (VendBankAccount.ExpiryDate > "8/8/2019 01:15:48 pm"))
However this doesn't filter the bank accounts that aren't expired at all.
Have spent a few hours on something that should really be trivial, any help would be appreciated,
Thanks
*This post is locked for comments
Beautiful mate,
I used option #1 in the tiles query, works great
I used option #2 in form datasources, works great
I used option #3 for computing charts results using while selects, works great, although I knew that one!
Thanks for your help, I had given up on #1 and #2... I think my main mistake was to expect a combined solution for #1 and #2 for both tiles and datasources... Works like a charm, eternally grateful!
Hi Greg,
Here are 3 different options. Either of these can be used to achieve your results.
Option1:
Here is the correct string to be built in QueryRangeFunction
return strFmt('(%1 = %2) || (%1 > %3)',
fieldStr(VendBankAccount, ExpiryDate),
queryValue(DateTimeUtil::minValue()),
queryValue(DateTimeUtil::utcNow()));
Option2:
Following query also gives correct results.
Query qr;
QueryBuildDataSource qbds;
qr = new Query();
qbds = qr.addDataSource(tableNum(VendBankAccount));
qbds.addRange(fieldNum(VendBankAccount, ExpiryDate)).value(queryValue(DateTimeUtil::minValue()));
qbds.addRange(fieldNum(VendBankAccount, ExpiryDate)).value(strfmt('>%1', DateTimeUtil::utcNow()));
Option3:
Create macro (%1.(%2) == %3) || (%1.(%2) > %4) and use it like this. It is also giving correct count of records.
select count(RecId) from vendBankAccount where #expiryDateQuery(vendBankAccount, fieldnum(VendBankAccount, ExpiryDate), DateTimeUtil::minValue(), DateTimeUtil::utcNow());
Ideally, I want to use this feature in both a form grid and a tile query, so that's why I made it a function with attribute QueryRangeFunction.
Hi Khushhal,
See this screenshot: https://imgur.com/paUHqrX
Nothing too fancy, I reproduced this issue very simply:
Added the method to Class1,
Created a new Form1, added VendBankAccount as datasource, added the filter in the init method, and dropped a few fields in the grid,
Date is 8/18 in US format, when the form opens, it shows all records in VendBankAccount, with mindate, with date<today and date>today.
Thanks
How are you using function BankAccountNotExpiredYet()? Can you provide some more info or screenshot where you are using this function? Since this function returns str type so can't be used directly with where clause so want to see how you are using it?
Also, modify following like below but it won't resolve your issue but this is the correct syntax to use these date values here.
SysQuery::value(DateTimeUtil::minValue()),
SysQuery::value(DateTimeUtil::utcNow());
Hi Khushhal,
I tried the following, but it generates the following error, hence I had added extra parenthesis and quotes.
Query extended range failure: Syntax error near 34.
QueryString for the query is:
SELECT FIRSTFAST * FROM VendBankAccount(VendBankAccount) WHERE ((( VendBankAccount.ExpiryDate = ) || (VendBankAccount.ExpiryDate > 8/18/2019 10:38:13 am)))
Regards,
Can you try this?
return strFmt('( %1.%2 = %3) || (%1.%2 > %4)',
TableStr(VendBankAccount),
fieldStr(VendBankAccount, ExpiryDate),
DateTimeUtil::minValue(),
DateTimeUtil::utcNow());
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,900 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156