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)

how to Join 2 tables in form ?

(0) ShareShare
ReportReport
Posted on by 576

hello.. 

i added a new dataSource in PurchLineOpenOrder Form

so , i want to create a new relation from PurchLine to EcoResProduct 

in init() method i added next lines , maybe the code is wrong !!

void init()
{
    QueryBuildDataSource    purchLineQbds,ecoResProductQbds;
    Query   query = new Query();
    
     purchLineQbds = query.dataSourceTable(tableNum(PurchLine));
     ecoResProductQbds = purchLineQbds.addDataSource(tableNum(EcoResProduct)); //line 7  
     ecoResProductQbds.joinMode(JoinMode::InnerJoin);
     ecoResProductQbds.relations(false);
     ecoResProductQbds.addLink(fieldNum(PurchLine, ItemId), fieldNum(EcoResProduct, DisplayProductNumber));    
    super();


but when form run the next error displayed

QueryBuildDataSource object not initialized.

Stack trace

(C)\Forms\PurchLineOpenOrder\Methods\init - line 7
(C)\Classes\SysSetupFormRun\init - line 3

*This post is locked for comments

I have the same question (0)
  • Crispin John Augustine Profile Picture
    37,081 on at

    The error is because, the objects that you have used willl not be initialized before super() of the init() Method.

    Second, this join Code is better in the form datasource init() method.

  • RaviRaj Profile Picture
    530 on at

    Hi Ismail,

    This not correct best practice and using table and fields do not have any relation.

  • Ismail Mohamed Profile Picture
    576 on at

    Crispin John Augustine

    Sorry can you explain the means of  initialized before super()

    Thanks

  • Crispin John Augustine Profile Picture
    37,081 on at

    all the form controls including the datasource queries are only initialized after super() is executed.

    In your case, you are already modifying the query before super, which is why AX promptly tells you ..."object not initialized"

    Move this Code to the datasource init method after super() and it's Problem solved.

  • Ismail Mohamed Profile Picture
    576 on at

    same error.

    init.png

  • Crispin John Augustine Profile Picture
    37,081 on at

    try in the EcoResProduct datasource init().

  • Ismail Mohamed Profile Picture
    576 on at
    public void init()
    {
    
         QueryBuildDataSource    purchLineQbds,ecoResProductQbds;
    
        super();
    
         ecoResProductQbds = this.query().dataSourceTable(tableNum(EcoResProduct));
         purchLineQbds= ecoResProductQbds.addDataSource(tableNum(Purchline));
         purchLineQbds.joinMode(JoinMode::InnerJoin);
         purchLineQbds.relations(false);
         purchLineQbds.addLink(fieldNum(EcoResProduct, DisplayProductNumber),fieldNum(PurchLine, ItemId));
    }

    No error but the relation not working fine , wrong names for all items

    Thanks

  • Crispin John Augustine Profile Picture
    37,081 on at

    May I ask, why do you want to connect to EcoResPRoduct from PurchLine? If item Name is all that you are looking for, there are better Options..

  • Ismail Mohamed Profile Picture
    576 on at

    Just i need to search by item name , so i don't need to use display method

    thanks

  • Crispin John Augustine Profile Picture
    37,081 on at

    OK, if that is the case, you can set joinsource on EcoResProduct to InventTable, and joinmode Innerjoin. No Code required.

    Inventtable is already joined to PurchLine. As simple as that.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans