title: Dynamics AX 2009: Displaying a name instead of an ID in a lookup field
body: <p>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.</p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>I realise that I can use a display method to show this, as per this question: <a href="https://stackoverflow.com/questions/1716694/axapta-lookup-field-display-the-string-value-instead-of-the-id">Axapta: Lookup field display the string value instead of the ID?</a>, but that will involve an unnecessary extra field, which I'd like to avoid if possible.</p>
  
  <p>Please could someone point me in the right direction?</p>