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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to join datasources with code?

(0) ShareShare
ReportReport
Posted on by 932

I add 2 datasources in form , then I add this code in the init method of form

    
    
    parmid                  = element.args().parm();
    query = new Query();
    queryBuildDataSource = query.addDataSource(tableNum(LoadLicenseLevel));
    queryBuildDataSource.addRange(fieldnum(LoadLicenseLevel,ParentMenuItem)).value(parmid);

    queryBuildDataSource1 = queryBuildDataSource.addDataSource(tableNum(TreeNode));
    queryBuildDataSource1.addRange(fieldnum(TreeNode,MatrixRole)).value(MatrixID.valueStr());
    queryBuildDataSource1.joinMode(JoinMode::InnerJoin);
    queryBuildDataSource1.relations(false);
    queryBuildDataSource1.addLink(fieldNum(LoadLicenseLevel, EukBrowsedMenuItems), fieldNum(TreeNode, SecurableName));

But I don't get the exact values.

I have the same question (0)
  • Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    Could you please provide a better description of your problem? "I don't get the exact values" can mean anything.

    Can you also show us how you're using the query? Because your code doesn't modify form's query - it creates a new independent query. If you don't explicitly set it to the form, all your code won't have any effect. But do you really want to create a new query instead of just filtering the automatically generated query? As usual, explaining what you're trying to achieve, instead of just showing a piece code, would help us to help you.

  • BASMA Profile Picture
    932 on at

    Hi Martin,

    I want to display informations in Grid based on 2 datasources.:

    4540.grid.png

    in the 1rst column I  get BrowsedMenuItems from the 1rst datasource.LoadLicenseLevel

    2. Based on BrowsedMenuItems I want  to search these values in TreeNode datasources (Column SecurableName ).

    When I get the correct informations (BrowsedMenuItems exists into TreeNode in the column SecurableName);

    I want to display the  securityLevel from TreeNode datasource.

    in the init method I add this code that I send later.

  • Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    Unfortunately you still haven't describe your problem, so let me at least improve your design.

    First of all, there is no TreeNode table and - as far as I can say - none can exist, because the name is already taken by TreeNode class. Can you please confirm that you have such a table? If you don't and your code won't even compile, than you should obviously fix this bug.

    Also, you don't need any code to add data sources and set the type of join. You seem to already have form datasources; then simply set JoinSource and Link Type properties on the child data source.

    Regarding the join relation, consider if you can't add it to child table. If you can all, you don't need addLink() either. All code you'll need is setting query ranges on the existing data sources.

  • BASMA Profile Picture
    932 on at

    The table TreeNode (customized table) exists

    I don't find any relations between the 2 tables

    rel.png

  • Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    If you really have two types with the same name (which I still struggle to believe), than your environment is a funny state and getting it fixed should be your top priority.

    If you don't have any relation and you want one, create it.

  • BASMA Profile Picture
    932 on at

    I dont understand you

    If you really have two types with the same name ??

  • Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    Dynamics AX contains a class called TreeNode. And you're saying that you also have a table with the same name, TreeNode. It shouldn't be possible, because than the same type name would mean two different things. How could you compile and run code without knowing which of the two types you should use?

  • BASMA Profile Picture
    932 on at

    the name is EUKTreeNode , juste I write TreeNode ;)

    I add relation between tables but I don't get any values now

  • Suggested answer
    Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    All right then, Next time, please make sure you compile your code and fix compilation errors.

    Please show us your current code and configurations of data sources. Also, look at the actual query string and verify that you have at least one record meeting all criteria.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 694

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 646 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 337

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans