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)

Altering a query in runtime

(0) ShareShare
ReportReport
Posted on by

Hello,heres  a scenario;

I have a query,which consists of some tables with some ranges and joins.In a form,I use this query,show it in a grid etc. no problem.

Now I want to add a button and a dateedit field to my form,and when the button is pressed, I want to refresh the query with the dateedit value.How can I achive that?

Currently tried the following but i get no results:

TransDate enddate;
Query q;
QueryBuildDataSource qdbs;
QueryBuildRange qbr;

enddate = TransDateEnd.dateValue();
q= InventTrans_1_ds.queryRun().query();
qdbs = q.dataSourceTable(tableNum(InventTrans));
qbr = qdbs.addRange(fieldNum(InventTrans,DatePhysical));
qbr.value("01\01\2014"); //hard coded for testing purposes.

InventTrans_1_ds.research(true);


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    see for inspiration

    dynamics-ax-live.blogspot.com/.../how-to-filter-records-in-form-by-code.html

  • Community Member Profile Picture
    on at

    Thanks, I'm trying to do the same thing with a button. I have tried it without a button, giving it hard-coded ranges, yet ,it does not filter the data.

    Btw,the form has a query as a datasource. Aand this query has joins and filters as it is.

    Could that be the problem? Do I have to reset the current ranges? However it may not be the best option since the query is very rigid as it is,and all I want to do is filter the data in inventtrans table with is a joined table in query.

    Regards.

  • Suggested answer
    Community Member Profile Picture
    on at

    Try this in your clicked method:

    inventTrans_ds.queryBuildDataSource().addRange(fieldNum(InventTrans, DatePhysical)).value(queryValue(DateEdit.dateValue()));

    inventTrans_ds.executeQuery();

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    you can check your query by following to know what is happening

    info(DatSourceName_ds.query().toString());

  • Suggested answer
    Community Member Profile Picture
    on at

    You need to declare a rang in Classdeclaration. In Init method of data source add the range if you have a value, in ExecuteQuery method add the range value before calling super.

    Finally in the clicked method of your button, call datasource init and executequery methods.

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