Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Sorting form with 2 data sources

Posted on by 50

Hello,

I have been searching this question for days and i could not find any answer. My question is:
I have 2 data sources in my form. And i have a grid. This data sources are joined to each other with inner join. I have fields of both Data Source on my grid. Now i want to sort this grid with following order:

ds1.Name
ds1.Surname
ds2.ExamDate

The grid Data Souce is ds1.
How can i sort with this way?

Thanks a lot;

*This post is locked for comments

  • badiyev Profile Picture
    badiyev 50 on at
    RE: Sorting form with 2 data sources

    Thanks Martin,

    This was exactly what i needed.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Sorting form with 2 data sources

    badiyev, you're right, it doesn't seem to work with addSortField(). Use addOrderByField() instead.

    Put this code to form's init() below super:

    tb2_ds.queryBuildDataSource().addOrderByField(fieldNum(tb2, SomeDate));
    tb2_ds.queryBuildDataSource().addOrderByField(fieldNum(tb2, SomeField));
    tb1_ds.queryBuildDataSource().addOrderByField(fieldNum(tb1, RecId));

    Tested on my box; it generates the right T-SQL code and (of course) returns expected data.

  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Sorting form with 2 data sources

    You could create a temporary table with an index that matches your field order, populate the records from the joined datasources, and use addSortIndex:

    msdn.microsoft.com/.../querybuilddatasource.addsortindex.aspx;MSPPError=-2147217396

    This is the only way probably that you could use to get it working.

  • badiyev Profile Picture
    badiyev 50 on at
    RE: Sorting form with 2 data sources

    Martin,

    When i use addSortField(), it only sorts for the field i provided latest.

    For example: I use:

    On init() of first ds:

        this.queryBuildDataSource().sortClear();

       ds2_ds.query().dataSourceTable(tableNum(tb2)).addSortField(fieldNum(tb2, SomeDate));

       ds2_ds.query().dataSourceTable(tableNum(tb2)).addSortField(fieldNum(tb2, SomeFIeld));

       this.query().dataSourceTable(tableNum(tb1)).addSortField(fieldNum(tb1, RecId));

    Here, only sort one is by table 1.recid . I want it to be sorted, first by SomeDate, then by SomeField, then by recid.

    Best regards.

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Sorting form with 2 data sources

    addSortField() does seem to be the answer. If you say it's not what you want, tell us why.

    Nobody replied because just saying "The question is what i am looking for" doesn't explain anything.

  • badiyev Profile Picture
    badiyev 50 on at
    RE: Sorting form with 2 data sources

    Martin, i am still facing with this problem, can you please suggest a solution?

    Best of Regards.

  • badiyev Profile Picture
    badiyev 50 on at
    RE: Sorting form with 2 data sources

    The question is what i am looking for.

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Sorting form with 2 data sources

    What are you looking for ?

  • badiyev Profile Picture
    badiyev 50 on at
    RE: Sorting form with 2 data sources

    hello ievgen,

    Thanks  for your suggestion and reply, but unfortunately this is not what i am looking for.

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Sorting form with 2 data sources

    Hi badiyev,

    Take a look at this community thread community.dynamics.com/.../127335

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans