Multi-Select Lookup on a Form with X++ Code
Introduction:
In today's fast-paced digital world, efficient data entry is crucial for businesses to streamline their operations. One common requirement is the ability to select multiple values from a lookup on a form. In this blog post, we will explore how to implement a multi-select lookup functionality on a form using X++ code. By the end of this article, you'll have the knowledge to enhance your forms with this powerful feature, making data entry a breeze.
Step 1: Setting up the Form
1.Let's add one dialogue form
Step 2: Adding the Multi-Select Lookup Control
1. add a string control
2. add ok and cancel buttons
Step 3: Populating the Lookup Values
1. override the control Lookup method
- declare Global variable for mult-select
- SysLookupMultiSelectCtrl mltSelectCtrl;
public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbd;
qbd = query.addDataSource(TableNum(yourTable));
qbd.addSelectionField(FieldNum(yourTable,Field1));
qbd.addSelectionField(FieldNum(yourTable,Field2));
qbd.clearRanges();
mltSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(this.formRun(),this,query);
}
Step 4: Selected values
- override the OK Click method, in the below method we are just displaying the selected values.
[Control("CommandButton")]
class OkButton
{
public void clicked()
{
container sRecid;
int i;
super();
sRecid = mltSelectCtrl.get();
for(i = 1; i <= conLen(sRecid) ; i++)
{
info(strFmt("selected %1 ", conPeek(sRecid,i)));
}
}