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
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.
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
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;
}
{
SysLookupMultiSelectCtrl msCtrl;
}
-------------------------------------------------------------------------------------------------------------
2.
public void init()
{
Query query = new Query();
super();
msCtrl = SysLookupMultiSelectCtrl::construct(element, S3_AccountTable_AccountNum, querystr(CustTablelookup));
}
{
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;
}
--------------------------------------------------------------------------------------------------------------
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();
}
----------------------------------------------------------------------------------------------------------------------{
// 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.

Comments
Post a Comment