Get Values From Dropdown Button of a StringEdit Control

Hi,

I’m new in AX 2009 using the developer section (AOT). I have successfully coded the list values I want to see in the dropdown list of the StringEdit control. I am having a problem on how can I get the specific selected value in the dropdown. I am planning to used to store in a variable or use it the WHERE statement of an SQL query. Please help!!!

Thanks,

Jeremy

How did you implement that lookup and what exactly do you want to do with it?

The code below is what I used in my lookup on a StringEdit control named “SONum”. I just want to get the value of the column name “ItemId” that I selected in the dropdown list and pass it in a variable so that I can used the variable in my where statement of SQL. Can you help me how to get the value I selected in “ItemId” column.

public void lookup()

{

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustPackingSlipTrans), this);

QueryBuildDataSource qb;

Query q=new Query();

;

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, SalesId),true);

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, PackingSlipId));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, DeliveryDate));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, ItemId));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, Name));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, Qty));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, SalesUnit));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, SalesGroup));

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, createdDateTime));

qb = q.addDataSource(tableNum(CustPackingSlipTrans));

q.allowCrossCompany(true);

q.addCompanyRange(“A”);

q.addCompanyRange(“B”);

q.addCompanyRange(“C”);

q.addCompanyRange(“D”);

q.addCompanyRange(“E”);

q.addCompanyRange(“F”);

qb.addGroupByField(fieldnum(CustPackingSlipTrans,PackingSlipId));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,SalesId));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,DeliveryDate));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,ItemId));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,Name));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,Qty));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,SalesUnit));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,SalesGroup));

qb.addGroupByField(fieldnum(CustPackingSlipTrans,createdDateTime));

qb.addOrderByField(fieldnum(CustPackingSlipTrans,DeliveryDate),1);

qb.addRange(fieldnum(CustPackingSlipTrans,DeliveryDate)).value(datetime2Str(CurrentDate.dateTimeValue()));

sysTableLookup.parmQuery(q);

sysTableLookup.performFormLookup();

}

Thanks,

Jeremy

You are not gonna get itemId from this code as you are using salesId to be displayed when you select a row from a lookup

If you just wanna use this code and nothing else, then you can use your above code with slight modification as

sysTableLookup.addLookupField(fieldNum(CustPackingSlipTrans, SalesId);

qb.addGroupByField(fieldnum(CustPackingSlipTrans,ItemId),true);

It will display the selected ItemId in your field

OR

you can just use simple select query to get Item Id associated with SalesId as:

CustPackingSlipTrans CustPackingSlipTrans;

ItemId Itemid;

Select CustPackingSlipTrans

where CustPackingSlipTrans.SalesId == SONum.valuestr();

Itemid = CustPackingSlipTrans.Itemid;

Now, the variable itemid stores the value of ItemId…

do let me knw if you get any issue with this…

1st set your SONum stringedit property value as Auto generation field as Yes

then use the above it will work

Thanks everyone, this may work!!! :wink: