Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to add range to View Datasource dynamically when the View is itself a datasource for a grid

Posted on by Microsoft Employee

hi,

Allow me to explain the situation.

I have a Table - SourceTable
SourceTable contains a 'Date', Field1, Field2

I have a View, AggView who's datasource is SourceTable.

The View dose not contain 'Date', but contains Field1 and Field2 + Aggregates the count of Field1, and the sum of Field2

The View is used for as a Datasource on a grid.

On my Form i can select dates.

I want to filter the View's data based on these dates.

How can I gain access to the Views DataSource to add a range? 

Is there a more efficient to doing this, (am guessing I could build the aggregated query for the view on the fly?)

Many thanks,

Rgds,

K.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    ok, got this sorted, i didnt add a query (with aggregrets) directly to the DS. I just added the raw table as ds and built the query on init and ranges on execute.

    all good, but not understanding the reason for the error above yet, but no biggie.

    thanks again for the input.

    rgds,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    Hi,

    I've created a query with the aggregates and group by fields (unsure if group by is needed, tried with and without them).
    When I add the query to the Form I receive the following error:

    AOT_5F00_AddQuery2DS_5F00_Error.JPG

    Anyways, not sure if this is the correct way to do what i need.
    Want to use the result of this (which i cant add to Form as a DS) as the data for a grid.
    Will see if i can manually attach it and roll the gird. :/

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    Thank you,

    Understood.

    I already have the DS Table in the form, which is used to display the un-aggregated data with range already applied after a select date range from controls.  I guess that using this exact DS is not the right way as it would impact the un-aggregated data. So I've added a query which i will code the range with after select. think is now how to add the results of the query to the Grid.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    You can filter views at will, in the same way as tables, but you can't modify views at runtime, because they, as tables, are defined in SQL Server, are shared across all user sessions (therefore adding a range would change the view for everybody) and you have to synchronize the database before the changes becomes visible.

    If I understand correctly, you want to add a filter to the query the view is based on, but that's not a feasible idea.

    If you want to filter values before aggregation and your view expose only aggregated data, it seems that the view doesn't meet your requirements and you should stop using it. Replace it with a query, where you can add both the range and aggregations.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    Hi Martin,

    If I can get access to the View's datasource then I could apply a range?

    I cant really add the date to the view's fields as it would make the aggregates incorrect (ie, it would display the aggregated per day, rather than for all)

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: How to add range to View Datasource dynamically when the View is itself a datasource for a grid

    I'm not completely sure what you're trying to achieve, but let me try...

    If you want to filter by Date field and the field isn't included in a query, it obviously can't be done - you can't filter by something that doesn't exist. You must add the field (not a range) to the view.

    When you have the field, you can modify the query used by the form by adding a range.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans