Hey all,
I created a new table with relations to the ProjInvoiceTable and LogisticsElectronicAddress:
I extended the form ProjInvoiceTable with a tab, containing a grid:
The Tab, grid, actionpane and actionpanetabs all have the new table I created and added as datasource (delayed linktype join to ProjInvoiceTable) as datasource property
I can now perfectly add records to the table via the form, that is working as intended.
However, once I click the D365 automatically created hyperlinks that get created I receive the error: 'Must be called with Common table buffer passed':
A good thing to note is that I did add a form eventhandler to make sure that the dropdown only shows contactinfo's of type email that correspond to the customers mentioned as the projectInvoices' projectfundingsource:
public final class FM_ProjInvoiceTable_EventHandlers
{
/// <summary>
/// Handles the OnLookup event for FM_LogisticsElectronicAddressLocator control
/// </summary>
/// <param name="sender">The form control</param>
/// <param name="e">Event arguments</param>
[FormControlEventHandler(formControlStr(ProjInvoiceTable, FM_LogisticsElectronicAddressLocator), FormControlEventType::Lookup)]
public static void FM_LogisticsElectronicAddressLocator_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query;
QueryBuildDataSource qbds;
QueryBuildDataSource qbdsLogisticsLocation;
QueryBuildDataSource qbdsDirPartyLocation;
QueryBuildDataSource qbdsLogisticsLocationRole;
QueryBuildDataSource qbdsCustTable;
QueryBuildDataSource qbdsProjFundingSource;
SysTableLookup sysTableLookup;
FormStringControl ctrl = sender as FormStringControl;
FormRun formRun = sender.formRun();
FormDataSource fdsProjInvoiceTable = formRun.dataSource(formDataSourceStr(ProjInvoiceTable, ProjInvoiceTable));
ProjInvoiceTable projInvoiceTable = fdsProjInvoiceTable.cursor();
// If no project invoice, allow default lookup
if (!projInvoiceTable.ProjInvoiceProjId)
{
return;
}
// Create the base query for LogisticsElectronicAddress
query = new Query();
qbds = query.addDataSource(tableNum(LogisticsElectronicAddress));
// Filter by Type = 2 (Email address)
qbds.addRange(fieldNum(LogisticsElectronicAddress, Type)).value(queryValue(LogisticsElectronicAddressMethodType::Email));
// Join to LogisticsLocation to connect with DirPartyLocation
qbdsLogisticsLocation = qbds.addDataSource(tableNum(LogisticsLocation));
qbdsLogisticsLocation.addLink(fieldNum(LogisticsElectronicAddress, Location), fieldNum(LogisticsLocation, RecId));
qbdsLogisticsLocation.joinMode(JoinMode::InnerJoin);
// Join to DirPartyLocation to link location with party
qbdsDirPartyLocation = qbdsLogisticsLocation.addDataSource(tableNum(DirPartyLocation));
qbdsDirPartyLocation.addLink(fieldNum(LogisticsLocation, RecId), fieldNum(DirPartyLocation, Location));
qbdsDirPartyLocation.joinMode(JoinMode::InnerJoin);
// Join to LogisticsLocationRole to filter by FM_DefaultOnProjectContract
qbdsLogisticsLocationRole = qbds.addDataSource(tableNum(LogisticsLocationRole));
qbdsLogisticsLocationRole.addLink(fieldNum(LogisticsElectronicAddress, ElectronicAddressRoles), fieldNum(LogisticsLocationRole, Name));
qbdsLogisticsLocationRole.joinMode(JoinMode::InnerJoin);
// Filter by FM_DefaultOnProjectContract = true
qbdsLogisticsLocationRole.addRange(fieldNum(LogisticsLocationRole, FM_DefaultOnProjectContract)).value(queryValue(NoYes::Yes));
// Join to CustTable to get customer party
qbdsCustTable = qbdsDirPartyLocation.addDataSource(tableNum(CustTable));
qbdsCustTable.addLink(fieldNum(DirPartyLocation, Party), fieldNum(CustTable, Party));
qbdsCustTable.joinMode(JoinMode::InnerJoin);
// Join to ProjFundingSource to filter by project funding sources
qbdsProjFundingSource = qbdsCustTable.addDataSource(tableNum(ProjFundingSource));
qbdsProjFundingSource.addLink(fieldNum(CustTable, AccountNum), fieldNum(ProjFundingSource, CustAccount));
qbdsProjFundingSource.joinMode(JoinMode::ExistsJoin);
// Filter by the current project
qbdsProjFundingSource.addRange(fieldNum(ProjFundingSource, ContractId)).value(queryValue(projInvoiceTable.ProjInvoiceProjId));
// Setup the lookup
sysTableLookup = SysTableLookup::newParameters(tableNum(LogisticsElectronicAddress), ctrl);
sysTableLookup.addLookupfield(fieldNum(LogisticsElectronicAddress, Locator));
sysTableLookup.addLookupfield(fieldNum(LogisticsElectronicAddress, Type));
sysTableLookup.addLookupfield(fieldNum(LogisticsElectronicAddress, Description));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
// Mark the event as handled to prevent default lookup
FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
ce.CancelSuperCall();
}
}
I thought D365 automatically created the hyperlinks as it also knows there is a relation but I figure Im just missing some kind of property that needs to be set?