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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Query filter cache

(0) ShareShare
ReportReport
Posted on by 1,559

Hi Friends,

I am running into problem. Which appears it's query filter issue.

I have a form, let user put in start/end date to query vendtable and vendtrans tables.

In form init() method, I initialize the start/end date for last month, then, user can change the date to whenever they want.

Problem I had is, whenever the date user change to, it always keep the last month data plus the data within date range user just put in.

I tried to clean the filter when button clicked, but, it doesn't work.

Any help is appreciated.

Here is my code:

This is from vendtable datasource executequery() method:

------------------------------

//filter on VendTrans table

diversifiedVendTransQBR2 = this.query().dataSourceTable(TableNum(VendTrans)).addRange(fieldNum(VendTrans, TransDate));

diversifiedVendTransQBR2.value(SysQuery::range(StartDate.dateValue(), EndDate.dateValue()));




This is from FORM init():




public void init()



{



super();



 StartDate.dateValue(prevMth(systemdateget()));



 EndDate.dateValue(systemdateget());



}




This is from button click method:




void clicked()
{
    VendTable_ds.removeFilter();
    VendTrans_ds.removeFilter();
    VendTable_ds.refresh();



    VendTable_ds.executeQuery();



    super();
}

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at
    RE: Query filter cache

    Hi Ganriver,

    In executeQuery() method add the following line of code 

    this.query().dataSourceTable(TableNum(VendTrans)).clearRange(fieldNum(VendTrans, TransDate));

    diversifiedVendTransQBR2 = this.query().dataSourceTable(TableNum(VendTrans)).addRange(fieldNum(VendTrans, TransDate));

    diversifiedVendTransQBR2.value(SysQuery::range(StartDate.dateValue(), EndDate.dateValue()));

    super();

  • Suggested answer
    Sukrut Parab Profile Picture
    71,699 Moderator on at
    RE: Query filter cache

    You can pass a value to range on button click method or on modified on start date and end date . I don't know business requirement behind initializing dates in init method.

    qbrCreatedDateTime.value(SysQuery::range(FromDate.dateValue(),ToDate.dateValue());

  • Verified answer
    Martin Dráb Profile Picture
    236,471 Most Valuable Professional on at
    RE: Query filter cache

    Unfortunately you didn't mention where you call the section "//filter on VendTrans table", but I'll assume it's in executeQuery(). Your code there always add a range, therefore if get executed ten times, you create ten ranges for the same field (with the same of different values). That's clearly wrong.

    Removing the range first (as shown by Rustem) is one possible way.

    Reusing the same range is the other. You can call addRange() in init() and storing the range in an instance variable or you can utilize SysQuery::findOrCreateRange().

  • Ganriver1 Profile Picture
    1,559 on at
    RE: Query filter cache

    Thank you Guys, that solved the problem.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans