I am creating a project in AX 2009 on a form. There is a lookup field called "SubsPersonName", which performs a lookup on the ContactPerson table using the following method.
public void lookup()
{
boolean ret;
Query query;
QueryBuildDataSource querybuilddatasource;
QueryBuildRange querybuildrange;
SysTableLookup sysTableLookup;
CustInvoiceAccount _thisinvoiceaccount = CustTable::find(CustTable::find(TTN_CustVendSubscriptions.AccountNum).InvoiceAccount).PartyId;
CustAccount _thisaccountnum = CustTable::find(TTN_CustVendSubscriptions.AccountNum).PartyId;
;
//TODO: Lookup value should read ContactPerson.Name, not ContactPerson.ContactPersonId
sysTableLookup = SysTableLookup::newParameters(tablenum(ContactPerson), this);
sysTableLookup.addLookupfield(fieldnum(ContactPerson, Name));
sysTableLookup.addLookupfield(fieldnum(ContactPerson, ContactPersonId), true);
sysTableLookup.addLookupfield(fieldnum(ContactPerson, CustAccount));
sysTableLookup.addLookupfield(fieldnum(ContactPerson, VendAccount));
query = new Query();
querybuilddatasource = query.addDataSource(tablenum(ContactPerson));
querybuildrange = querybuilddatasource.addRange(fieldnum(ContactPerson, Name));
querybuildrange = querybuilddatasource.addRange(fieldnum(ContactPerson, OrgPartyId));
if (!_thisinvoiceaccount)
_thisinvoiceaccount = _thisaccountnum;
querybuildrange.value(strfmt("%1,%2", _thisinvoiceaccount,_thisaccountnum));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
The code above works fine, but I need to adjust it slightly. The value that needs to be inserted into the database is ContactPerson.ContactPersonId as per this code, but I would like the field in the form to display ContactPerson.Name.
I realise that I can use a display method to show this, as per this question: Axapta: Lookup field display the string value instead of the ID?, but that will involve an unnecessary extra field, which I'd like to avoid if possible.
Please could someone point me in the right direction?