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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Join form data sources by code in X++

(0) ShareShare
ReportReport
Posted on by

I have tow form data sources and they do not have direct relation between them i.e. both of them have direct relation to HcmWorker.

how can I join these data   sources by code i.e. without using properties of form data sources ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    In the init method of formDatasource you can add the HcmWorker as new datasource(using querybuilddatasource) and use methods addLink, relations to join it by accessing the form query. Join the other datasource to this query in its init method.

  • Suggested answer
    Srini Ramidi Profile Picture
    2 on at

    Here is the nice post on the same topic.

    community.dynamics.com/.../how-to-add-a-range-or-data-source-to-a-form-data-source

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Typically your code would like following:

    1. Declare querybuildDatasource object in the class declaration of the form.

      querybuildDatasource hcmWorkerDS;

      Query       query;

    2. In the executequery method of the datasource1, add HCMworker to it.

       query = FormDatasouce1.query();

        hcmWorkerDS  = query.addDataSource(tableNum(HCMWorker));

        hcmWorkerDS.addLink(fieldNum(Table1, CommonField), fieldNum(HcmWorker,

        CommonField)); // Here assumed Table1 to be parent and HcmWorker as child

        hcmWorkerDS .joinMoIde(JoinMode::InnerJoin);

        hcmWorkerDS relations(false);

    3. In executequery method of datasource2, use the same code as above only by making

      HCMWorker as parentTable and Table2 as childTable.

  • maram fraij Profile Picture
    on at

    I determine the join data source property on the child data source in addition to  link

    type.

    in execute query of the parent data source and before super I add the below code

    ParentDataSource_ds.query().dataSourceName("ChildDataSource").linkFields("ParentField","ChildField");

    this piece of code is used to determine joining fields  since there is no direct  relation between data sources

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans