Skip to main content

Notifications

Announcements

No record found.

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

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

    Thank you Guys, that solved the problem.

  • Verified answer
    Martin Dráb Profile Picture
    233,587 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().

  • Suggested answer
    Sukrut Parab Profile Picture
    71,687 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
    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();

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans