Store id and display name on single field

hello all,

I want Emloyee id to be stored in table and want to display employee name on form. so i tried following method.

  1. i had created lookup using following code

SysMultiTableLookup sysTableLookup;

Query query;

QueryBuildDataSource qbdsHcmWorker,qbdsDirPerson;

;

query=new Query();

qbdsHcmWorker=query.addDataSource(tableNum(HcmWorker));

qbdsDirPerson=qbdsHcmWorker.addDataSource(tableNum(DirPerson));

qbdsDirPerson.relations(true);

qbdsDirPerson.fetchMode(QueryFetchMode::One2One);

sysTableLookup = SysMultiTableLookup::newParameters(_formControl,query);

sysTableLookup.addLookupfield(fieldnum(HcmWorker,personnelNumber),1);

sysTableLookup.addLookupfield(fieldnum(DirPerson, Name),2);

sysTableLookup.performFormLookup();

So it will display me emp_id and name on my lookup. lookup is displaying perfect.

  1. Now I want to store Empid in table but want to display Name on form level so i had written following code in edit method of data source and applied this method as a data method on form control.

public edit DirPartyName editApproverId(boolean _set,GBIRulesGroupTable _GBIRulesGroupTable,HcmPersonnelNumberId _EmpId)

{

HcmWorker hcmWorker;

DirPartyName partyName;

;

hcmWorker=HcmWorker::findByPersonnelNumber(_EmpId);

//BP deviation documented

if(_set)

{

mytable.myfield=_EmpId

}

partyName= DirPerson::find(hcmWorker.Person).Name;

return partyName;

}

from my hand it is looking fine. but problem is it is not storing,displaying any value for field. And when i select values from lookup i am not able to see on form.

Your design is not what you should use.

You should store the surrogate key of HcmWorker table (HcmWorkerRecId EDT), displaying it through ReferenceGroup control and choosing the right replacement field group.

hello martin,

I can’t understand what you are trying to say. can you describe in detail?

Thanks,

Hardik

All right, I’ll explain it in more details in a blog post. Give me some time; I’ll update this thread with a link as soon as it’s done.

Blog post: Replacement groups in AX 2012.

Hi Martin,

I have a similar issue.

But instead of storing RecId in table I want to store a custom field Id.

Is it possible through this approach?

Thanks,

Surbhi Agrawal

The reference field must have type Int64. If your custom field has a different type, you can’t use it.