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

Announcements

News and Announcements icon
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

    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,741 Moderator on at

    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
    239,680 Most Valuable Professional on at

    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

    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dserp Profile Picture

dserp 4

#2
dekion Profile Picture

dekion 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans