Skip to main content

How to write lookup for selecting multiple options

Before Writing code we have to create string in form Right click on group and now go to string add

Name it diffrent or we can add lable later

create lookup method override

First set the ReplaceOnLookup property of the control to “NO”

Second set the control Autodeclartion property to “Yes”


[Control("String")]

    class FormStringControl1

    {

        /// <summary>

        ///

        /// </summary>

        public void lookup()

        {

            SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(Food), this);

            Query query = new Query();

            QueryBuildDataSource qbds;

            


            sysTableLookup.addLookupField(fieldnum(Food,FoodName  ), true);

            qbds = query.addDataSource(tablenum(Food));


            this.setSelection(strlen(this.text()),strlen(this.text()));

            FormStringControl1.text(FormStringControl1.valueStr() + ',');


            sysTableLookup.parmQuery(query);


            sysTableLookup.performFormLookup();

            super();


        }


        /// <summary>

        ///

        /// </summary>

        /// <returns></returns>

        public boolean modified()

        {

            boolean ret;

        

            ret = super();

            Box::info(strFmt("%1",FormStringControl1.text()));


            if(FormStringControl1.text() != '') //Check the combo box has value or not


            {


                SysQuery::findOrCreateRange( Food_ds.query().dataSourceTable( tableNum( Food )),


fieldNum( Food,FoodName  ) ).value( SysQuery::value( FormStringControl1.text() ) );


            }


            

            else


            {


                SysQuery::findOrCreateRange( Food_ds.query().dataSourceTable( tableNum( Food )),


fieldNum( Food,FoodName   ) ).value( SysQuery::valueUnlimited() );


            }


        

            Food_ds.executeQuery();

            return ret;

        }


    }


    [Control("String")]

    class FormStringControl2

    {

        /// <summary>

        ///

        /// </summary>

        public void textChange()

        {

            super();

            this.modified();

        }


        /// <summary>

        ///

        /// </summary>

        /// <returns></returns>

        public boolean modified()

        {

            boolean ret;

        

            ret = super();


            str nameFilter;


            nameFilter = '*'+this.text()+'*';

            Food_ds.filter(fieldnum(Food,FoodType  ),nameFilter);

        

            return ret;

        }


        /// <summary>

        ///

        /// </summary>

        public void enter()

        {

            super();


            this.setSelection(

                strlen(this.text()),

                strlen(this.text()));

        }


    }

Comments

Popular posts from this blog

Total Amount of Purchase Order in X++

Method 1:  public AmountCur totalAmount()        // PurchLine       purchLine;         AmountCur       amountCur = 0;         while select crosscompany purchLine             index hint PurchLineIdx             where purchLine.PurchId         == purchtables.PurchId               && !purchLine.IsDeleted         {            // amountCur += purchLine.calcLineAmountExclTax(purchLine.PurchQty );                             amountCur += purchLine.calcLineAmount(purchLine.PurchQty + purchLine.ConfirmedTaxAmount );                          }         return amo...

Change Company

change company helps to chnage the value of our field on the mark of the entity value  suppose you are overding a value in 3005 when you change to 1005 and click button the value changes in 1005 too   class LegalEntityRestriction_FYCDeleteExistingEntries     {         /// <summary>         ///         /// </summary>         /// <returns></returns>         public boolean modified()         {             boolean ret;                      //ret = super();             LedgerParameters ledgerparameter;                  ret = super();             if(LegalEntityRestriction_FYCDeleteExistingEntries.valueStr( ) == enum2Str(NoYes::Yes))   ...

Chain of Command

Chain of command is used to write extension of code for a standard Table or Form which we need to be overwrite and make changes according to ours   Chain of command can be used in the following objects 1.Classes 2.Tables 3.Forms 4.Data source on a form. 5.Data field on a form. 6.Control of a form. 7.Data entities Steps to Follow in COC Step1: Name of the chain of command class we create must end with the _Extension. Step2: The keyword ‘final’ must be used in the class definition line. Step3: The class needs to have the attribute        [ExtensionOf(classStr(<NameOfBaseObject>))]    The “ classStr ” text above will change depending on the type of base objecting you are extending. -> Below are the extensions used based on where we are using chain of commands.  -> When extending a class, use classStr(<NameofBaseClass>) -> When extending a table, use tableStr(<NameOfBaseTable>) -> In the case of a form, use formStr(...