Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

how to refresh multi selected lookup in form control ?

(0) ShareShare
ReportReport
Posted on by 920

Hello, 

I   add multi selected lookup to a field in datasource ,

when Iopen form and I create new record , i get the lookup, I chose values 

But the problem is when I add second record , I get the same values selected as the first in lookup

[Form]
public class ShippingModeTable extends FormRun
{
    
    SysLookupMultiSelectCtrl    msCtrl;
    public Query buildDlvModeQuery()
    {
        Query       dlvModeQry = new Query(queryStr(ShippingModeLookup));
        return dlvModeQry;
    }

    container getSelectedCodes(str _codeStr)
    {
        DlvMode    dlvMode;
        container   tmpValues, conIds, conName;
        int         idx;
     
        if(_codeStr)
        {
            tmpValues = str2con(_codeStr, ';');
        }
     
        for(idx=1; idx<=conLen(tmpValues); idx  )
        {
            dlvMode = DlvMode::find(conPeek(tmpValues, idx));
            conIds  = dlvMode.RecId;
            conName  = dlvMode.Code;
        }  
        return [conIds, conName, conIds];
    }

    [DataSource]
    class ShippingModeTable
    {
        [DataField]
        class ShippingMode 
        {
            /// 
            ///
            /// 
            public void modified()
            {
                ShippingModeTable    shippingModeTable    = ShippingModeTable_ds.cursor();   
                shippingModeTable.ShippingMode     =   con2Str(msCtrl.getSelectedFieldValues(), ';');
                ShippingModeTable_ds.refresh();
                ShippingModeTable_ds.research(true);
            }

            public void lookup(FormControl _formControl, str _filterStr)
            {
                //super(_formControl, _filterStr);
                Query               dlvModeQry         =   element.buildDlvModeQuery();
                FormStringControl   shippingMode        =   element.design().controlName('ShippingModeTable_ShippingMode');
                EOLEShippingModeTable    shippingModeTable    =   ShippingModeTable_ds.cursor();
                msCtrl   = SysLookupMultiSelectCtrl::construct(element,
                                            shippingMode,
                                            querystr(ShippingModeLookup),
                                            false,
                                            [tableNum(DlvMode), fieldNum(DlvMode,Code)]);
                  msCtrl.set(element.getSelectedCodes(shippingModeTable.ShippingMode));
                ShippingModeTable_ds.refresh();
                ShippingModeTable_ds.research(true);
            }

        }

    }

}


pastedimage1677313643600v1.png

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to refresh multi selected lookup in form control ?

    hello HARISH MEHRA 

    sorry for the late response ,

    Yes, I found a solution

    [Form]
    public class ShippingModeTable extends FormRun
    {  
        SysLookupMultiSelectCtrl    msCtrl;
        ShippingModeTable    shippingModeTable;
        /// 
        /// get the  mode od delivery from dlvMode Table
        /// 
        /// 
        /// container of selected element in lookup
        container getSelectedCodes(str _codeStr)
        {
            DlvMode    dlvMode;
            container   tmpValues, conIds, conName;
            int         idx;    
            if(_codeStr)
            {
                tmpValues = str2con(_codeStr, ';');
            }   
            for(idx=1; idx<=conLen(tmpValues); idx  )
            {
                dlvMode = DlvMode::find(conPeek(tmpValues, idx));
                conIds  = dlvMode.RecId;
                conName  = dlvMode.Code;
            }
            return [conIds, conName, conIds];
        }
    
        public void init()
        {
            super();
            msCtrl   = SysLookupMultiSelectCtrl::construct(element,
                                                ShippingModeTable_ShippingMode,
                                                querystr(ShippingModeLookup));
        }
    
        [DataSource]
        class ShippingModeTable
        {
            /// 
            ///update lookup's values
            /// 
            /// 
            public int active()
            {
                int ret;       
                ret = super();
                shippingModeTable    =   ShippingModeTable_ds.cursor();
                msCtrl.set(element.getSelectedCodes(shippingModeTable.ShippingMode));
               return ret;
            }
    
            [DataField]
            class ShippingMode 
            {
                /// 
                /// update values in ShippingModeTable
                /// 
                public void modified()
                {
                    shippingModeTable.ShippingMode     =   con2Str(msCtrl.getSelectedFieldValues(), ';');
                }
    
            }
    
        }
    
    }

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: how to refresh multi selected lookup in form control ?

    Hello BASMA did you get the answer. Because I am also facing the same issue.

    Help will be appreciated.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to refresh multi selected lookup in form control ?

    hello,

    Andre Arnaud de Calavon , no I have 3 fields in table , I store  the selection in a string field

    then this is all the code that I add it .

    Mohit Rampal , I see this code and I use it , the problme with this code is how to set the eventHandler npt static

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: how to refresh multi selected lookup in form control ?

    Hi Basma,

    Check this article, try aligning with code mentioned there.

    erpdax.wordpress.com/.../

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,111 Super User 2025 Season 1 on at
    RE: how to refresh multi selected lookup in form control ?

    Hi Basma,

    Is the coding you shared all the coding related to this lookup? Have you implemented coding to update the selected values on the active() method of the data source?

    Do you only have Shipping mode field on this table (where you store the selection in a string field) or also an additional table to store the relations between this table and the Mode of delivery?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans