Skip to main content

How to select multiple value from lookup in ax 2012

Hi,

Today we will see how to select multiple value from dropdown lookup.

In this case we will select multiple customer account num.

Step 1: Create a query

Step 2 : In this example I have created a table  but you can use existing one. I have added one field account number.
Step 3 : As I have created a new table , so I have to create new form too. Again you can continue with existing form.


Step 4 : Now Add below method in form methods

1.

public class FormRun extends ObjectRun
{
SysLookupMultiSelectCtrl msCtrl;
}
-------------------------------------------------------------------------------------------------------------
2.

public void init()
{
Query query = new Query();
super();
msCtrl = SysLookupMultiSelectCtrl::construct(element, S3_AccountTable_AccountNum, querystr(CustTablelookup));
}
---------------------------------------------------------------------------------------------------------------
3.

public int task(int _taskId)

{

#task

int ret;

ret = super(_taskId);


if (ret && _taskId == #TaskSave)
{
msCtrl.get();




}

return ret;


}

 
--------------------------------------------------------------------------------------------------------------


Step 5 : You have to do some customization in "SysLookupMultiSelectCtrl" class.

Copy and Paste below code in SysLookupMultiSelectCtrl in below listed methods.

1. init() and 2.  ctrlNames_textChange()


public void init()
{
// Added by Pramod
boolean isOnGrid(FormStringControl _ctrl)
{
FormControl parentControl;
FormControl currentControl;
boolean retValue;
currentControl = _ctrl;
retValue = false;
while(currentControl.parentControl() && !retValue)
{
parentControl = currentControl.parentControl();
if(parentControl is FormGridControl)
retValue = true;
else
currentControl = currentControl.parentControl();
}
return retValue;
}
// Addded by Pramod end
frmRun.lock();
fsCtrlIds = frmRun.design().addControl(FormControlType::String, fsCtrlNames.name() + '_Ids');
fsCtrlIds.extendedDataType(fsCtrlNames.extendedDataType());
fsCtrlNamesTmp = frmRun.design().addControl(FormControlType::String, fsCtrlNames.name() + '_Tmp');
fsCtrlNamesTmp.extendedDataType(fsCtrlNames.extendedDataType());
// set the value in ctrlNames to the same as the one in the original ctrl. Required if data is loaded from SysLastValue.
fsCtrlNamesTmp.text(fsCtrlNames.valueStr());
// Added by Pramod on 15 Sept 2016 started
if(isOnGrid(fsCtrlNames))
{
fsCtrlNames.registerOverrideMethod('modified', 'ctrlNames_textChange', this);
}
else
{
fsCtrlNames.registerOverrideMethod('textChange', 'ctrlNames_textChange', this);
}
// end
// fsCtrlNames.registerOverrideMethod('textChange', 'ctrlNames_textChange', this);
fsCtrlNames.registerOverrideMethod('lookup', 'ctrlNames_lookup', this);
fsCtrlIds.visible(false);
fsCtrlNamesTmp.visible(false);
fsCtrlIds.enabled(false);
fsCtrlNamesTmp.enabled(false);
fsCtrlNames.mandatory(isMandatory);
fsCtrlNames.lookupButton(FormLookupButton::Always);
frmRun.resetSize();
frmRun.unLock();
}
----------------------------------------------------------------------------------------------------------------------
public void ctrlNames_textChange(FormStringControl _fsCtrlNames)



{

// _fsCtrlNames.text(fsCtrlNamesTmp.text());


// fsCtrlNames.modified();



FormDataSource fds;

Common anyBuffer;

_fsCtrlNames.text(fsCtrlNamesTmp.text());

fds = _fsCtrlNames.dataSourceObject();

if(fds)



{

anyBuffer = fds.cursor();

anyBuffer.(_fsCtrlNames.dataField()) = fsCtrlNamesTmp.text();

fds.refresh();

}

fsCtrlNames.modified();

}

--------------------------------------------------------------------------------------------------------------------
Step 7: Now check the result.


Thanks

Comments

Popular posts from this blog

How to change client Language in ax 2012

Hello,  As you know that Dynmics Ax run on different languages. So I gonna tell you how to change client language country/region specific. this is nothing but a very simple step to do. Go To > File > Tools > Options > After that go to General tab and select the language which you want to use in your client. then apply and exit. In my case I was using Arabic language. Now restart your client and see the difference. You can do it from your database also . Go to Database server  . In my case it is sql server 2014. Select your database > tables > UserInfo > select the user > change the language code. Done Thanks.

Simple x++ query with enum value range

static void queryEnumValue(Args _args) {     Query                   query;     QueryRun                queryrun;     QueryBuildDataSource    qbds;     QueryBuildRange         qbr;     PurchTable              purchTable;     ;         query = new Query();         qbds = query.addDataSource(tableNum(PurchTable));     qbds.addSortField(fieldNum(PurchTable, PurchId), SortOrder::Ascending);     qbr     = qbds.addRange(fieldNum(PurchTable, PurchStatus));         qbr.value(enum2str(PurchStatus::Received));         queryrun = new QueryRun(query);         while(queryrun.next())     {         purchTable = query...

Unit Conversion by code in ax 2012 R3 , X++

static void unitConversion() {     SysExcelApplication xlsApplication;     SysExcelWorkBooks xlsWorkBookCollection;     SysExcelWorkBook xlsWorkBook;     SysExcelWorksheets xlsWorkSheetCollection;     SysExcelWorksheet xlsWorkSheet;     SysExcelRange xlsRange;     SysExcelCells Cells;     SysExcelCell RCell;     CommaIO inFile;     int nRow,i;     DialogField dialogPath;     Dialog dialog;     Filename filename;         UnitOfMeasureConversion             unitOfMeasureConversion;     UnitOfMeasure                       unitOfMeasure;     EcoResProduct                       ecoResProduct;     RecId               ...