web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 59

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

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 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

  • Suggested answer
    Hossein.K Profile Picture
    6,648 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
    Hossein.K Profile Picture
    6,648 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

  • Patryk Mi Profile Picture
    59 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?



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

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

  • Mea_ Profile Picture
    60,284 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
    59 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
    60,284 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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
NNaumenko Profile Picture

NNaumenko 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans