1

I have unbound field on a form. Right now i am showing a look-up on that field using a look-up method which shows All distinct values from a field in a table. Now i changed that name field in table to Recid field. Now i need to display look-up with names but when i select one value i want to show name on U I but i have to select Recid. I don't want recid to display in look-up. How can i achieve that?

Before i used to get lookup of name using this method like this

public void lookup() {

SysTableLookup       sysTableLookup =   SysTableLookup::newParameters(tablenum(RTTable), this);
Query                query = new Query();
QueryBuildDataSource queryBuildDataSource;
;

sysTableLookup.addLookupfield(fieldnum(RTTable, AsstManager));
queryBuildDataSource = query.addDataSource(tablenum(RTTable));
queryBuildDataSource.addSortField(fieldnum(RTTable, AsstManager));
queryBuildDataSource.addRange(fieldNum(RTTable, AsstManager)).value(queryNotValue(''));
queryBuildDataSource.orderMode(ordermode::GroupBy);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

super();

}

Raas
  • 261
  • 8
  • 25

2 Answers2

2

You need .addSelectionField(...), and most likely to remove the super() line.

See these links for some examples:

https://daxbeginners.wordpress.com/tag/lookup-table/

http://dynamicsuser.net/forums/p/56634/303103.aspx

Ah, I forgot also you can specify the return field in the optional second argument of: sysTableLookup.addLookupfield(fieldnum(RTTable, AsstManager), TRUE);

See second argument at https://msdn.microsoft.com/en-us/library/systablelookup.addlookupfield.aspx

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • .addSelectionfield() doesnot work. I tried with addSelectionfield for AsstMgrID but eventhough its UI and backend its taking the AsstMgr name only. I need on UI the name and on backend its ID to be used. – Raas Apr 27 '15 at 04:46
  • 1
    This is a standard feature of AX 2012. Your RecId has to be used as a surrogate key and the field you want to display as the replacement key. As it's an unbound field, you have to set the link on the EDT. So create a new Int64 EDT extanding RefRecId and set it to refer to your table. – Geoffrey DELMEE Apr 27 '15 at 05:35
  • Can you explain little clearly. I am confused. Recid has to be used a surrogate key means? (Do i need to give ASstMgrRecid field in table as PrimaryIndex for that table?) THe field ASSTmgrName which i want to display should be used in Replacement key? I need to create EDT and use it for the unbound field? – Raas Apr 27 '15 at 05:52
  • See this for Surrogate keys: https://msdn.microsoft.com/en-us/library/hh812105.aspx And this: https://community.dynamics.com/ax/b/axrajdipdas/archive/2013/04/16/how-to-create-and-implement-of-surrogate-keys-in-ax2012 – Jan B. Kjeldsen Apr 27 '15 at 06:54
  • Hi I used form lookup and achieved this. – Raas Apr 28 '15 at 03:06
  • I just updated the answer with some more information. You have to set the 2nd parameter to "true" to set the return item. – Alex Kwitny Apr 30 '15 at 21:42
0

You can do it by having a custom lookup form and using the CloseSelect() method on the form. There you can put in the code to return your recId

Kenny Saelen
  • 894
  • 1
  • 5
  • 16