Axapta V/s Me

Yet another blog for Dynamics 365 for Finance and Operations. This blog primarily targets the technical readers. I will be sharing my experience with Dynamics AX using code snippets, errors, and solutions, Tips, and tricks.

Join Two Tables at Run Time

Join Two Tables at Run Time

static void theAxapta_JoinTables(Args _args)
    Query                     query;
    QueryBuildDataSource      queryBuildDataSource1,
    QueryBuildRange           queryBuildRange;
    QueryBuildLink            queryBuildLink;
    // Create a new query object
    query = new Query();
    // Add the first data source to the query
    queryBuildDataSource1 = query.addDataSource(tablenum(CarTable));
    // Add the range to this first data source
    queryBuildRange = queryBuildDataSource1.addRange(fieldnum(CarTable, ModelYear));
    // Add the second datasource to the first data source
    queryBuildDataSource2 =   queryBuildDataSource1.addDataSource(tablen
    // Add the link from the child data source to the
    //parent data
    queryBuildLink = queryBuildDataSource2.addLink(fieldnum(CarTable,
    CarId),fieldnum(RentalTable, CarId));

This process (query through X++ code) is very similar to create a query directly through AOT node.
AOT -> Query -> Right Click -> New Query
I would suggest first create a query through query node, than go for this code.


No comments:

Post a Comment


Note: Only a member of this blog may post a comment.