So I wanted a way to open the CustInvoiceJournal form and only show invoices that are tagged with a ProjectId that corresponds to the selected Project on the parent form. In other words, duplicate the functionality that you get from Inquiries - Tax Invoice button on the Sales Table Form but look for a ProjectId instead of an SalesId.
Buried inside the CustInvoiceJour Data Source init method I found the code it uses
if (element.args().dataset() == tablenum(SalesTable)) { this.query().dataSourceTable(tablenum(CustInvoiceJour)).addRange(fieldnum(CustInvoiceJour, RefNum)).value(queryValue(RefNum::SalesOrder)); this.query().dataSourceTable(tablenum(CustInvoiceJour)).clearDynalinks(); queryDataSourceLink = this.query().dataSourceTable(tablenum(CustInvoiceJour)).addDataSource(tablenum(CustInvoiceSalesLink)); queryDataSourceLink.relations(true); queryDataSourceLink.addDynalink(fieldnum(CustInvoiceSalesLink, OrigSalesId), element.args().record(), fieldnum(SalesTable, SalesId)); }
So I added in a bit after it
if (element.args().dataset() == tablenum(HIL_ProjectTable) && element.args().caller().name() == formstr(HIL_ProjectTable)) { this.query().dataSourceTable(tablenum(CustInvoiceJour)).clearDynalinks(); queryDataSourceLink = this.query().dataSourceTable(tablenum(CustInvoiceJour)).addDataSource(tablenum(HIL_ProjectTable)); queryDataSourceLink.relations(true); queryDataSourceLink.addDynalink(fieldnum(CustInvoiceJour, HIL_ProjectId), element.args().record(), fieldnum(HIL_ProjectTable, ProjectId)); }
But when I click on my Inquiries - Tax Invoice button in my Projects table I get this error message in the log
Error executing code: Wrong argument types for comparison.
(C)\Classes\QueryRun\next
(C)\Classes\FormDataSource\executeQuery
(C)\Classes\FormDataSource\linkActive
If I remove the queryDataSourceLink.addDynalink command it opens without the error message (but displays all invoices with a valid HIL_ProjectId)
so it feels like my addDynalink command is wrong... but for the life of me I can't work out how.
I added in a breakpoint and checked the element.args().record() that's being fed to it, but it seems fine and shows a valid projectId.
Both the HIL_ProjectId in the CustInvoiceJour Table and the ProjectId in the HIL_ProjectTable are the same HIL_Project Extended Data Type.
I've added a relation to the data dictionary on my HIL_Project Table linking to the CustInvoiceJour...
I'll try a full recompile tonight but I don't think I've ever had issues with Forms & Tables before. When classes are involved it seems to get more complicated.
Any ideas?