September 06, 2013

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.