Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to make relations in views

(0) ShareShare
ReportReport
Posted on by 55

Hi!
Some problems with relations in views (AX 2009), maybe someone can help me?

I have two SQL powered views 

  1. SalesView - data from SalesTable with join to CustTable
  2. SalesLineView - data from SalesLine with join to InventTable

and want to put them both in one form with relation. I mean if you click on SalesView record it updates grid with SalesLineView fields. 
In tables on form case, it's just need to set JoinSource property to right table name (e.g. SalesTable for SalesLine), but this logic don't work on views for me. 
Can it be done at all? 

*This post is locked for comments

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: how to make relations in views

    No, I did not. This line   " l = s.addDataSource(tableNum(pmi_salesline_view));" adds new data source, so, yes, you are adding it when you should not. ANd you should not do it in executeQuery, it should be done in init.

  • Patryk Mi Profile Picture
    Patryk Mi 55 on at
    RE: how to make relations in views

    You misunderstood me, I didn't add new datasource, I just said where i put this code.

    When I putting code in init method i have error:

    Error executing code: FormDataSource object not initialized.

    (C)\Classes\FormDataSource\Query

    (C)\Forms\Form3\Methods\init

    (C)\Classes\SysSetupFormRun\init - line 11

    Sorry for my lame question, I'm new in AX

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: how to make relations in views

    Why do you add new datasource? You need to add 2 data source in the form desginer, set join mode. They would not have auto relation created by AX, so in init method you will set it using addLink.  

  • Patryk Mi Profile Picture
    Patryk Mi 55 on at
    RE: how to make relations in views

    Hossein, maybe I am wrong, but I think that I'm using left join :)

  • Patryk Mi Profile Picture
    Patryk Mi 55 on at
    RE: how to make relations in views

    Thanks for answers guys! AddLink is that what i was looking for.

    Unfortunately, if i use this code:

    public void executeQuery()
    {
        QueryBuildDataSource s;
        QueryBuildDataSource l;
        Query query;
        ;
    
        query = pmi_sales_view_ds.Query();
        s = query.dataSourceTable(tableNum(pmi_sales_view));
        l = s.addDataSource(tableNum(pmi_salesline_view));
        l.joinMode(JoinMode::InnerJoin);
        l.fetchMode(QueryFetchMode::One2Many);
        l.relations(false);
        l.addLink(fieldNum(pmi_sales_view, SalesId), fieldNum(pmi_salesline_view, SalesId));
        info(query.xml());
    }


    it doesn't work, but i haven't any errors in log.

    I have put that code into Data Sources > PMI_salesline_view > Methods

    What I'm doing wrong?



  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,646 on at
    RE: how to make relations in views

    For customization,use this link:

    community.dynamics.com/.../how-joins-in-x-select-statement-are-translated-into-t-sql

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,646 on at
    RE: how to make relations in views

    Hi Patryk Mi,

    AX does not do a right join. You can put your "right" table as top of the select statement, and do an outer join on the "left" table. This way it will return all rows as a SQL right join would for the right table, and only rows that match based on the relation from the left table.Results are identical to what you would expect with a right join.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: how to make relations in views

    You cannot do it from form designer because it uses relations defined in AOT and you cannot have them for view but you can do it using x++ code, on init method using addLink method, please refer this thread for details

    community.dynamics.com/.../123239

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

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,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans