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)

Dynalink not being created with correct Table References

(0) ShareShare
ReportReport
Posted on by 130

OK, I've no idea how this can be going wrong. It seems like Dynamics is deliberately disobeying my my code.
Here is the relevant part.

if (element.args().dataset() == tablenum(ProjectLine))
{
this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)).clearDynalinks();
queryDataSourceLink = this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)).addDataSource(tablenum(ProjectLine));
queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,ProjectId),element.args().record(),fieldnum(ProjectLine, ProjectId));
queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,CustAccount),element.args().record(),fieldnum(ProjectLine, CustAccount));
}

When the query runs the Dynalinks created are on ProjectLine.ProjectId == ProjectLine.ProjectId and ProjectLine.CustAccount == ProjectLine.CustAccount
Which is obviously useless.

I threw a breakpoint on the second addDynalink command and took a look at the value of the queryDataSourceLink and saw this: 

SELECT * FROM ProjectLine WHERE ProjectLine.ProjectId=ProjectLine.ProjectId

Any idea why/how Dynamics can ignore the part in bold where I specify a totally different Table? 

queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,ProjectId),element.args().record(),fieldnum(ProjectLine, ProjectId));

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Daniel Weichsel Profile Picture
    on at

    In your code, queryDataSourceLink is added based on ProjectLine (newly added data source).  You then take this same data source and add a dynalink to another ProjectLine record (the one referenced through args).  It is likely a coincidence that the field IDs are the same for ProjectId and CustAccount on both of your tables.


    I expect that you want something like this instead, where you add the dynalinks to the ProjectCustomerQuotation data source:

    if (element.args().dataset() == tablenum(ProjectLine))
    {
    	this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)).clearDynalinks();
    	queryDataSourceLink = this.query().dataSourceTable(tablenum(ProjectCustomerQuotation)); // Not adding a new data source
    	queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,ProjectId),element.args().record(),fieldnum(ProjectLine, ProjectId));
    	queryDataSourceLink.addDynalink(fieldnum(ProjectCustomerQuotation,CustAccount),element.args().record(),fieldnum(ProjectLine, CustAccount));
    }


  • Adam Duckworth Profile Picture
    130 on at

    Yep, as soon as I removed the ProjectLine datasource it all worked as it should.

    Much appreciated. And two things learnt really

    1. You don't need to add the parent table as a "secondary" datasource to have a Dynalink on it.

    2. Check field ID's in future.

    Thanks!

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