Monday, 17 July 2023

Multi-Select Lookup on a Form with X++ Code D365 FO

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


  1. declare Global variable for mult-select 
  2. 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 

  1. 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)));

            }  


    }

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...