Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Report result does not change after adding range to the data source from code

(0) ShareShare
ReportReport
Posted on by 15

Hi

I have added three tables as report data source (InventTable, InventTrans, InventDim)

then I added date field to the dialog

and I want to add this date filter to the current query

I have created this method

private Query buildPeriodQuery()
{
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    Query                   queryBuild;
    ;
    queryBuild              = new Query(this.query().pack());
    queryBuildDataSource    = queryBuild.dataSourceTable(tablenum(InventTrans));
    queryBuildRange         = SysQuery::findOrCreateRange(queryBuildDataSource, fieldnum(InventTrans, DatePhysical));
    queryBuildRange.value(queryRange("", toDate));
    
    info(queryBuildDataSource.toString());
    
    return queryBuild;
}

Then I called it in getFromDialog

public boolean getFromDialog()
{

    ;
    
    toDate = dlgToDate.value();
    
    this.buildPeriodQuery();

    return true;
}

and this is the query result

SELECT FIRSTFAST * FROM InventTrans 
WHERE InventTable.ItemId = InventTrans.ItemId 
AND ((DatePhysical<={ts '2021-02-01 00:00:00.000'})) 
JOIN FIRSTFAST * FROM InventDim 
WHERE InventTrans.inventDimId = InventDim.inventDimId

But the date filter does not affect the report result

Thanks in advance.

  • Khaled_Fahim Profile Picture
    15 on at
    RE: Report result does not change after adding range to the data source from code

    Thank you Martin this solves my problem

    Actually I'm a C# developer and I'm trying to deal with AX as much as I can

    Thanks.

  • Verified answer
    Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Report result does not change after adding range to the data source from code

    Isn't the right approach simply changing the query you get from this.query()? It's not clear to me why you're creating a copy instead and changing this copy.

    This would be my approach:

    Query                   queryBuild = this.query()
    QueryBuildDataSource    queryBuildDataSource = queryBuild.dataSourceTable(tablenum(InventTrans));
    QueryBuildRange         queryBuildRange = SysQuery::findOrCreateRange(queryBuildDataSource, fieldnum(InventTrans, DatePhysical));
    ;
    queryBuildRange.value(queryRange("", toDate));

    By the way, using queryRange() is correct if you want a range of dates until toDate.

  • Khaled_Fahim Profile Picture
    15 on at
    RE: Report result does not change after adding range to the data source from code

    Hi Anucha

    Actually I wanted it <= toDate

    queryBuildRange.value(queryRange("..", toDate));

    Thanks

  • Community Member Profile Picture
    on at
    RE: Report result does not change after adding range to the data source from code

    Hi Khaled

    Please change queryrange function to queryvalue because you use 1 parameter. queryrange must send 2 parameters.

  • Khaled_Fahim Profile Picture
    15 on at
    RE: Report result does not change after adding range to the data source from code

    Yes I got your point but I don't know what shall I do next to let the new query affect report result

    is there something like this.query = my new query.

    Thanks.

  • Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Report result does not change after adding range to the data source from code

    Sure, you have the query, but you're not using it. The object stops existing at the end of buildPeriodQuery() method and it has absolutely no impact on your report or anything else.

  • Khaled_Fahim Profile Picture
    15 on at
    RE: Report result does not change after adding range to the data source from code

    Hi Martin

    I just wanted to filter transactions in InventTrans table before the report fetches the data and send it to the report.

  • Verified answer
    Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Report result does not change after adding range to the data source from code

    You've added a range and returned the modified query from buildPeriodQuery(), but then you ignore the return value, therefore it has no effect. Didn't you want to assign the value to a variable?

  • Khaled_Fahim Profile Picture
    15 on at
    RE: Report result does not change after adding range to the data source from code

    Hi André

    Thank you for your reply

    It is a new custom report from scratch.

    The report shows Item group, Number, Name, Dimensions from my three tables.

    and on-hand quantity and posted cost as a display methods in X++ for filtered transactions on a specific date selected by user

    When I select date from dialog query select button every thing works well. but when I use created date dialog field the data  does not change

  • André Arnaud de Calavon Profile Picture
    292,961 Super User 2025 Season 1 on at
    RE: Report result does not change after adding range to the data source from code

    Hi Khaled,

    Can you elaborate on the contents of this report? Is it a standard report which got customized or a new custom report from scratch? What details are to be shown on the report? Do you have more methods with x++ coding on this report?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,961 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans