web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Not expired Query Range for bank accounts

(0) ShareShare
ReportReport
Posted on by 4

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

I have the same question (0)
  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    Can you try this?

    return strFmt('( %1.%2 = %3) || (%1.%2 > %4)',

            TableStr(VendBankAccount),

            fieldStr(VendBankAccount, ExpiryDate),

            DateTimeUtil::minValue(),

            DateTimeUtil::utcNow());

  • MagVesse Profile Picture
    4 on at

    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,

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    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());

  • MagVesse Profile Picture
    4 on at

    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

  • MagVesse Profile Picture
    4 on at

    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.

  • Verified answer
    Khushhal Garg Profile Picture
    1,514 on at

    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());

  • Suggested answer
    MagVesse Profile Picture
    4 on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans