Select multiple records from lookups in Dynamics AX 2012
Select multiple rows from lookups by using a SysLookMultiSelectCtrl class.
public class FormRun extends ObjectRun
{
SysLookupMultiSelectCtrl msCtrl;
}
Override the init method of the form and place the below code
public void init()
{
super();
// TestCtrl - Name of control on which you want a lookup.
// StudentCourse - Query to get the lookup data
msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));
}
Select multiple records from the lookup.
To get the values and RecId of the selected rows records, override the modified method of the TestCtrl control and add the below code.
public boolean modified()
{
boolean ret; container c,v;
int i;
ret = super();
if (ret)
{
c = msCtrl.get(); // get RecIds of the selected rows
v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows for (i = 1; i <= conLen(c);i++)
{
info(conPeek(c,i));
info(conPeek(v,i));
}
} return ret;
}
Create a Query named StudentCourse that will contains 2 datasources i.e Student &Course as shown in the below figure.
Now create a new form named MultiSelectLookupCtrl and add a StringEdit control named as TestCtrl in the design node.Set its AutoDeclaration property to "Yes"
Now override the following methods and write the following code.
In the ClassDeclaration of the form write the below code.
{
SysLookupMultiSelectCtrl msCtrl;
}
Override the init method of the form and place the below code
public void init()
{
super();
// TestCtrl - Name of control on which you want a lookup.
// StudentCourse - Query to get the lookup data
msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));
}
Select multiple records from the lookup.
To get the values and RecId of the selected rows records, override the modified method of the TestCtrl control and add the below code.
public boolean modified()
{
boolean ret; container c,v;
int i;
ret = super();
if (ret)
{
c = msCtrl.get(); // get RecIds of the selected rows
v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows for (i = 1; i <= conLen(c);i++)
{
info(conPeek(c,i));
info(conPeek(v,i));
}
} return ret;
}
No comments:
Post a Comment