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

DataSource filter and Datasource join in form when a filter option need it

(0) ShareShare
ReportReport
Posted on by 15

Hi everyone. I do have a big problem finding how to resolve this situation. First of all I have to explain that I'm a begginer with Dynamics AX.

This is the thing:

I have a form with a lot datasources, the principal is Principal_DataSource, and we have a Second_DataSource.

I have a filer option for the data in the grid. This filter filters the content of Principal_DataSource when Second_DataSource.value3 == combobox.valuStr(); The linktype of Second_DataSource with  Principal_DataSource  is Delayed.

I'm getting crazy because a see in he forum a lot options like this inside executequery of Principal_DataSource :

qb = this.query().dataSourceTable(tableNum(Principal_DataSource)).addDataSource(tableNum(Second_DataSource));
        qb.joinMode(JoinMode::InnerJoin);
        qb.addLink(fieldNum(Principal_DataSource, value1),fieldNum(Second_DataSource, value1));

But when I do it It doesn`t work at all. After that I have to put 2 addRange, so Its a bit crazy, and ofcourse I don`t know how to delete the source Second_DataSource to Principal_DataSource when this filter is disabled.

Other option that i was thinking about It's to use Principal_DataSource_ds.filter() but I don´t know how to filter ds with a query.

Thank You for your help.

  • Alain.z Profile Picture
    Alain.z 15 on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    Hi  Martin Dráb.

    With this option I realized that when you push the save button from froms toolbar, It throws a warning message, telling to introduce same field values. When I didn´t have these 2 tables and the realtion created, It worked fine. Any idea how to avoid this?

    Thank you very much.

    ************

    SOLUTION

    ************

    I found another way to make this work without any issue, or creating tables second data source...

    Inside form classDeclaration create:  query   tableQuery;

    Inside form init: tableQuery = firstTable.query();

    Inside form datasource firstTable.executeQuery():

                  this.query(new Query(tableQuery ));

    This way you can add datasources and joins and whatever you want.

  • Alain.z Profile Picture
    Alain.z 15 on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    Thank you very much. I made a mistake and I put another option instead of enabled. And I had the executequery of table1 before this instead of after.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,407 Most Valuable Professional on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    No, you can't change JoinSource. As I suggested in the last sentence of my first reply, you can disable the query data source by enabled() function. For example: Table2Copy_ds.queryBuildDataSource().enabled(false).

    Alternatively you could change the type of join (e.g. to outer join), but it sounds inefficient.

  • Alain.z Profile Picture
    Alain.z 15 on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    Thank you again.

    I realizes later abou this. The point It's that If make the relations from the init the grid appears filtered:

    Table1

    Table2 joinSource table1 linktype delayed

    Table2Copy joinSource table1 linktype existsjoin

    Can I change the joinSource of table2copy whenever I want? Can I put Null joinsource I when i need to filter add table1?

    Or active and deactive the relations whenever I want?

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,407 Most Valuable Professional on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    Sorry, I must have explained something in a wrong way. Let me address the filter once more.

    You can't use your current Second_DataSource to filter Principal_DataSource, because of the Deplayed link. But you want to do that, therefore you need one more data source. One DS for Second_DataSource table is the only your already have. And you'll add one more DS for the same table, as ExistsJoin, and add a range to this data source.

    There is no reason to duplicate your 19 data sources; what we're doing here is just adding the one data source that you'll use for filtering of Principal_DataSource.

  • Alain.z Profile Picture
    Alain.z 15 on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    Thank you for the answer.

    I have a principal grid where appear all the requests for a service, so if a change the join type between this 2 data sources,  in the grid will not appear all the requests, there will appear what a I need todo only when I active the filter.

    This second data source It's the info about all the requests that have incidences. I have a tab where appears the incidences too, so that's why i have a delayed link, because I want to show the incidences only when the selected record have any incidence.

    When I active the filter option, in the grid (only when I filter) must be appear the requests that have incidences. When I deactive the filter, in he grid have to appear again the previous data.

    I have like 19 data source in the form related with Principal_DataSource , because i have a lot of tabs with info about, client, request, documents... So If I do like you said and put another data source, I supose that I have to add a copy of all data sources. Maybe I'm wrong It's what i understand.

    I think the easier way must be filtering Principal_DataSource_ds, with "select Second_DataSource.value1 from Second_DataSource where Second_DataSource.value3 == "xyz" " and when I deactive the filter I only have to delete filter or recharge the info.  But again, I don´t know how to filter a ds with query records.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 231,407 Most Valuable Professional on at
    RE: DataSource filter and Datasource join in form when a filter option need it

    A delayed link doesn't allow you to filter the parent data source. If you need both a filter and a delayed link, you indeed need two data sources. The best type of join would be Exists join, because you use it just for filtering and you don't need to fetch any fields.

    Adding the data source at runtime is possible; just make sure you don't add it more than once. If you call addDataSource() every time the query gets executed, you can soon end up with many data sources. Another (and easier) approach is adding a third data source in form's definition. By the way, if there is a relation between data sources, you could simply use qb.relations(true) instead of addLink().

    Make sure you're adding the range to the right data source. If something doesn't work, look at the actual database query used by the form. Again, don't add it more than once.

    When you want to remove the filter, either set the range value SysQuery::valueUnlimited(), or disable the query data source (using QueryBuildDataSource.enabled() method).

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…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans