web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

EDT's and table relations

(0) ShareShare
ReportReport
Posted on by 110

I'm a newbie at AX and a little bit puzzled ...

As an exercise I'm developing a little call registrattion applic in AX2009

Extended DataTypes: CallID (related to Calls.CallID), CallCat (related to CallCategories.CallCat).

I did not define any relations for the tables.

Table Calls, fields CallID, CallDesc, CallCat and some more fields. The ExtendedDataTypes CallID and CallCat are used!

Table CallCategories, fields CallCat, CallCatDesc. The ExtendedDataType CallCat is used!

I created a query qryCalls (datasource Calls, under it datasource CallCategories (jointype innerjoin)).
When I run the query from a job I get a Cartesian product (all calls will be related to all callcategories).

Only when I define in the query the relation between calls and callcategories the output of the query is OK.

So what's the use of the InnerJoin. Do I really have to (re)define the relation I already specified at the ExtendedDataTypes?

Next I created a report Calls. Datasource qryCalls. AutoDesign. I clicked GenerateDesign and two Body were created (one for Calls, one for Categories)

I want to have all Calls fields and the CallCatDesc on one line, so I moved all fields to the Calls Body.

When I ran the report the wrong CallCatDesc was shown (or no CallCatDesc at all).

Only when I move the CallCatDesc to the Body for Categories the report will shown the correct output.

So what should I do to get the report I want (all fields on one line)?

Next I created a form Calls (datasources Calls and CallCategories (joinsource calls, jointype delayed).

Two tabpages: One Overview (a grid showing all calls), one Details (all fields of one Call)

Moving the CallCatDesc to the Overview only works OK if I set the jointype to InnerJoin. So why was it set at delayed in the first place?

I guess I'm missing some crucial point here. Could anyone clarify to me why AX does what it does?

Thx in advance ...

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    "I did not define any relations for the tables."

    You should!

    Under table Calls assigned a relation to CallCategories on CallCat.  Recreate your report and form.

  • Henny Sol Profile Picture
    110 on at

    I DID set relations on my Extended Data Types! According to the documentation -as I understand it- the relations set at the EDT's wille be valid as long as they are not overruled by relations defined at the table.

    If I define relations at the table what's the use of relations defined at the EDT???

  • Jonathan Havard Profile Picture
    on at

    Henny,

    I believe I can explain the behavior you're experiencing.

     

    I created a query qryCalls (datasource Calls, under it datasource CallCategories (jointype innerjoin)).

    When I run the query from a job I get a Cartesian product (all calls will be related to all callcategories).

    Only when I define in the query the relation between calls and callcategories the output of the query is OK.

    The solution to this issue is to on the DataSource object within your query, set the property 'Relations' to YES.  After you save, inspect the 'Relations' node underneath the DataSource, and you will notice the relations have been copied into the 'Relations' node based on your table relations.  I believe this will dynamically update based on your table relations.

     

     

    Next I created a report Calls. Datasource qryCalls. AutoDesign. I clicked GenerateDesign and two Body were created (one for Calls, one for Categories)

    I want to have all Calls fields and the CallCatDesc on one line, so I moved all fields to the Calls Body.

    When I ran the report the wrong CallCatDesc was shown (or no CallCatDesc at all).

    Only when I move the CallCatDesc to the Body for Categories the report will shown the correct output.

    So what should I do to get the report I want (all fields on one line)?

    The cause of your issue is that at the time the report prints the section, the tableBuffer for CallCatDesc is stale.  On the Body report section, you may notice the 'Table' property.  The 'Table' property specifies which tableBuffer, when sent (send() was called) will trigger the respective section.  The reason why all your fields are correct when you move the report controls to a different section is because the 'Table' property on that section is set to a tableBuffer which is sent last, so every other tableBuffer has been updated to the latest record.  Reference the fetch() report method on axaptapedia.com or another resource for more information on what I'm referring to here.

    Moving the CallCatDesc to the Overview only works OK if I set the jointype to InnerJoin. So why was it set at delayed in the first place?

    The reason why your fields work correctly when the 'JoinMode' property is set to 'Inner Join' is because 'Inner Join' will immediately fetch the joined records for every record in the parent table. 'Delayed' JoinMode will only fetch records which are related to the currently active parent table record ONLY.  The reason why 'Delayed' is a default is because it performs better for most standard AX-style forms (with a header / line style).  Basic idea here is to use 'Inner Join' for when you want to have fields from several tables on the same grid.  Use 'Delayed' when you have two related grids.

     

    I DID set relations on my Extended Data Types! According to the documentation -as I understand it- the relations set at the EDT's wille be valid as long as they are not overruled by relations defined at the table.

    If I define relations at the table what's the use of relations defined at the EDT???

    Your understanding is correct.  If you specify the relations on the Extended Data Types there is no reason to add the same exact relations onto the Table.  From my experience, if a relation to the same related table is on an Extended Data Type and a Table,  AX will honor one, but not the other.  I don't think it consistently chooses the Table relation (although I would agree that would make sense).

     

    Hope this helps,

     

  • Henny Sol Profile Picture
    110 on at

    Thanks Jonathan, your answers are very clear:

    On the Query I did miss the Relation property. Now I understand, although I think that defaulting it to No is silly, since I created a relation.

    My call register applic has also a table CallPeople (PersID, PersName, Telephone). I created a EDT PersID with a relation to CallPeople.PersID. From my Calls table 3 fields are related to the CallPeople table: ReportedBy, SpiderInTheWeb, ActionBy

    If I add only one CallPeople table to the qryCalls (parallel to CallCategories (same level)), modify my job to print the PersName and run qryCalls from the job each call is reported a number of times (some cartesian product though all relations are set).

    When I drop 3 CallPeople tables all the relations that are generated go from ReportedBy to the CallPeople table. The CallPeople datasources are numbered sequentially (1,2,3). How can I reference the PersName field of the third CallPeople datasource in my job (I use infolog printing in the job).

    Is the thing I want (3 relations to the same table) possible using only drag-and-drop or is some X++ coding necessary

    Thx in advance & I'm sure it will help ...

  • Verified answer
    Jonathan Havard Profile Picture
    on at

    On the Query I did miss the Relation property. Now I understand, although I think that defaulting it to No is silly, since I created a relation.

    I agree completely.  Defaulting to the already-defined relations would make more sense.

     

    My call register applic has also a table CallPeople (PersID, PersName, Telephone). I created a EDT PersID with a relation to CallPeople.PersID. From my Calls table 3 fields are related to the CallPeople table: ReportedBy, SpiderInTheWeb, ActionBy

    If I add only one CallPeople table to the qryCalls (parallel to CallCategories (same level)), modify my job to print the PersName and run qryCalls from the job each call is reported a number of times (some cartesian product though all relations are set).

    Ok, let me sure I understand the issue clearly.  On your Calls table, your fields ReportedBy, SpiderInTheWeb, and ActionBy all have EDTs set to PersID.  There are no explicit table relations on these fields or to the CallPeople table (only implicit by the EDT relation).  When you add the CallPeople table to your query, joined to Calls table, your relations don't work correctly.  A couple things I would try:  1) change the 'FetchMode' on your CallPeople datasource to '1:1' instead of '1:n'. 2) Verify the relations in the 'Relations' node are what you would expect.  If there are 3 relations to the CallPeople table, I'm not sure which relation (if any) AX will pick if you set 'Relations' = YES.  It would be best under these circumstances to explicitly define your relations in your query.

     

    When I drop 3 CallPeople tables all the relations that are generated go from ReportedBy to the CallPeople table. The CallPeople datasources are numbered sequentially (1,2,3). How can I reference the PersName field of the third CallPeople datasource in my job (I use infolog printing in the job).

    Is the thing I want (3 relations to the same table) possible using only drag-and-drop or is some X++ coding necessary

    As I said in my above response,  I recommend explicitly setting your relations to what you want them to be.  I'm not really sure what your job looks like so if I'm wrong, post some example code so I can help you better.  I assume you're iterating your query with something like:

    while (queryRun.next())
    {
    CallPeople = queryRun.get(tablenum(CallPeople)); 

    The queryRun.get() method takes an optional parameter to specify which occurrence of the datasource you want, so change your code to say:

    CallPeople = queryRun.get(tablenum(CallPeople), 3);

     

    Hope this helps,

     

  • Henny Sol Profile Picture
    110 on at

    Your crystalclear answers helped me a lot. Thanks!

    Setting the FetchMode to 1:1 did the trick. I had already wondered about this FetchMode property.

    Strange that:

    * when the query only has the Calls and the CallCategories datasources there is NO problem.

    * when I add 1 CallPeople datasource I have to set the FetchMode to 1:1 for both datasources. And since it is possible that ReportedBy, SpiderInTheWeb and ActionBy are still empty I had to change the JoinType to OuterJoin. But now it's OK.

    I still wonder about how AX is in fact processing ...

    Thank you so much!

  • Henny Sol Profile Picture
    110 on at

    Hi Jonathan,

    Referencing the 3rd CallPeople datasource in the way you suggested results in the message 'Datasource is not enabled'. If I change all occurrences to 1 (see below) the query runs fine.  So what am I missing...

    I checked the qryCalls query. Datasource Calls_1. Under it datasources CallCategories_1, CallPeople_1, CallPeople_2, CallPeople_3 (all on the same level). All relations are OK.

    static void RunQuery(Args _args)
    {
        QueryRun                qryrun;
        Calls                   calls;
        CallCategories          callCategories;
        CallPeople              ReportedBy;
        CallPeople              SpiderInTheWeb;
        CallPeople              ActionBy;
        ;

        qryrun = new QueryRun(QueryStr(qryCalls));
        if (qryrun.prompt())
        {
            while (qryrun.next())
            {
                calls = qryrun.get(tablenum(calls));
                callCategories = qryrun.get(tablenum(callCategories));
                ReportedBy = qryrun.get(tablenum(callPeople),1);
                SpiderInTheWeb = qryrun.get(tablenum(callPeople),1);
                ActionBy = qryrun.get(tablenum(callPeople),1);
                info(int2str(calls.CallID)+" / "+calls.CallDesc+" Rep: "+ReportedBy.PersName+" Spider: "+SpiderInTheWeb.PersName+" Act: "+ActionBy.PersName+"... Categorie:"+ callCategories.CallCatDesc);
            }
        }
    }

  • Suggested answer
    Jonathan Havard Profile Picture
    on at

    Henny,

    The first thing I'd check there is a property on your CallPeople datasources inside your qryCalls query.  Datasources all have properties called 'Enabled' and if one of them is set to NO you'll get the error you mentioned when you try to access the datasource at runtime.

    If it's not that, perhaps you should send me an XPO so I can take a better look.

    Thanks,

  • Henny Sol Profile Picture
    110 on at

    I already checked the Enabled property, Jonathan. It was OK on all datasources. I'll investigate further. When I feel defeated I'll send you an XPO.

    Thx for the quick response ...

  • Henny Sol Profile Picture
    110 on at

    The problem is fixed!

    Having 3 relations from the Calls to the CallPeople table is rather difficult for AX. I defined the relation to the CallPeople table only at the PersID EDT (which should be enough). Dropping 3 CallPeople tables in the qryCalls query, having Relation set to YES didn't work OK. AX kept resetting the relation on all 3 CallPeople datasources to Calls.ReportBy -> CallPeople.PersID. I changed the relations a couple of times, but AX did reset it (after some (?) time).

    I fixed this doing the following: I defined the correct 3 relations at the Calls table. In the qryCalls query I set Relation=NO on the 3 datasources, FetchMode 1:1, JoinType OuterJoin and I defined the correct relations for these datasources.

    Now the job that runs qryCalls gives the correct output (I can reference the 3rd datasource via: ActionBy = qryrun.get(tablenum(CallPeople),3);).

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans