SBX - Search With Button

SBX - Forum Post Title

Link VS DynaLink

Microsoft Dynamics AX Forum

Eitan Mizrahi asked a question on 11 Oct 2011 2:34 PM
My Badges

Question Status

Suggested Answer

Hello.

I need to know about the differences between Link and Dynalink.

Need a simple example of:

Link in code two tables, and ignore the default link between them.

i.e SalesTable + SalesLine ...

Connect them by some other column (or columns).

 

Thanks :)

Reply
Joris de Gruyter responded on 11 Oct 2011 3:30 PM
My Badges
Suggested Answer

Below an example. Feel free to change the link. The infolog will show the xml representation of the query, which I've found to be helpful in debugging sometimes.

   Query                   query;

   QueryBuildDatasource    datasource;

   ;

   query = new Query();

   // Add SalesTable main datasource

   datasource = query.addDataSource(tableNum(SalesTable));

   // Add child datasource "SalesLine" to previously created DS

   datasource = datasource.addDataSource(tableNum(SalesLine));

   // Indicate you don't want to use relations automatically

   datasource.relations(false);

   // Add link between parent field and child field

   datasource.addLink(fieldNum(SalesTable, SalesId), fieldNum(SalesLine, SalesId));

   info(query.xml());

Reply
gl00mie responded on 11 Oct 2011 9:56 PM
My Badges
Suggested Answer

A link creates a join (inner by default) between two QueryBuildDatasources of the same query. Data from the corresponding tables is fetched simultaneously, in a single query to the database. A dynalink creates additional where clauses on a data source, and its data is fetched in a  subquery - separately from the dynalinked data source. Dynalinks are a great feature of Dynamics AX that allows data in different forms to be "synchronized" while you navigate through data on one form.

Reply
Eitan Mizrahi responded on 17 Oct 2011 4:57 AM
My Badges

The function addDynalink takes 3 arguments.

The second argument is "common _DynamicFile" - What is it for?

Thanks ;)

Reply
Joris de Gruyter responded on 17 Oct 2011 5:59 AM
My Badges
Suggested Answer

Dynalink will update a query based on a "live" table buffer. This is used between forms, as gl00mie explained, so if you have two forms open one form will update it's query if you select a different record on the other. This is achieved by adding a dynalink on a specific field, and passing in the record (common) to trigger from. I don't see this being useful in a regular query object, although I must assume it works (I never tried).

You can see this process in action for example if you go to inventory management > item details and click on "transactions". Leave the transactions form open but select a different item in your item details screen. AX automatically does dynalinking a lot on forms, based on the args.record() being passed along.

Reply
Eitan Mizrahi responded on 17 Oct 2011 8:34 AM
My Badges

In form: custPackingSlipJournal, dataSource: custPackingSlipJour, method: init, there is a code behind.

I want to understand that code ... and can I do the Dynalink otherwise (I want to do the same, but limit it to a specific item).

Thanks :)

Reply
Joris de Gruyter responded on 11 Oct 2011 3:30 PM
My Badges
Suggested Answer

Below an example. Feel free to change the link. The infolog will show the xml representation of the query, which I've found to be helpful in debugging sometimes.

   Query                   query;

   QueryBuildDatasource    datasource;

   ;

   query = new Query();

   // Add SalesTable main datasource

   datasource = query.addDataSource(tableNum(SalesTable));

   // Add child datasource "SalesLine" to previously created DS

   datasource = datasource.addDataSource(tableNum(SalesLine));

   // Indicate you don't want to use relations automatically

   datasource.relations(false);

   // Add link between parent field and child field

   datasource.addLink(fieldNum(SalesTable, SalesId), fieldNum(SalesLine, SalesId));

   info(query.xml());

Reply
Joris de Gruyter responded on 17 Oct 2011 5:59 AM
My Badges
Suggested Answer

Dynalink will update a query based on a "live" table buffer. This is used between forms, as gl00mie explained, so if you have two forms open one form will update it's query if you select a different record on the other. This is achieved by adding a dynalink on a specific field, and passing in the record (common) to trigger from. I don't see this being useful in a regular query object, although I must assume it works (I never tried).

You can see this process in action for example if you go to inventory management > item details and click on "transactions". Leave the transactions form open but select a different item in your item details screen. AX automatically does dynalinking a lot on forms, based on the args.record() being passed along.

Reply

SBX - Two Col Forum

SBX - Migrated JS