Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Multi select column in Sales Table form.

(0) ShareShare
ReportReport
Posted on by 100

28501.Capture.PNG

[Extensionof(formstr(SalesTable))]
final class SalesLine_CAP_Extension
{  

    [FormControlEventHandler(formControlStr(SalesTable, SalesLine_ManufacturingPlant_CAP), FormControlEventType::Lookup)]
    public static void SalesLine_ManufacturingPlant_CAP_OnLookup(FormControl sender, FormControlEventArgs e)

    {
        Args args;
        FormRun formRun;
        MultiSelectionHelper Msh;
        InventSite inventSite;
        FormDataSource              salesLine_ds = sender.formRun().dataSource(formDataSourceStr(SalesTable, SalesLine));
        SalesLine                 salesLine = salesLine_ds.cursor();
        str store;

        int                                  i, conLength;
        int64                                recId;
        SysLookupMultiSelectValues           delimitedControlValues;
        container                            controlValues;
        container                            selectField;

        FormStringControl d = sender.formRun().design().controlname(formControlStr(SalesTable, SalesLine_ManufacturingPlant_CAP));
        FormDataSource inventSite_ds;
        FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
        //Add the categorymultiselectlookupfilter as an argument for lookup
        args = new args(formStr(InventSite));
        //Add the current conrol (Grid Column) as lookup caller
        args.caller(d);
       
        formRun = classFactory.formRunClass(args);
        //Initialize and perform lookup form
        formRun.init();
        d.performFormLookup(formRun);
        inventSite_ds = formRun.dataSource();       
        delimitedControlValues = d.text();      
        if(delimitedControlValues)
        {
            controlValues = str2con(delimitedControlValues, ';', false);
            conLength = conlen(controlValues);
            for (i = 1; i <= conLength; i  )
            {
                
                inventSite_ds.findRecord(InventSite::find(conpeek(controlValues, i)));
                inventSite_ds.mark(true);
              
            }
        }
       

        formRun.wait();
        if(formRun.closedOk())
        {
            Msh = MultiSelectionHelper::construct();
            Msh.parmDatasource(inventSite_ds);

            for (InventSite = inventSite_ds.getFirst(true) ? inventSite_ds.getFirst(true) : inventSite_ds.cursor();inventSite;
            InventSite = inventSite_ds.getNext())
            {
                store  = InventSite.SiteId ";";
            }
            d.text(store);
            
            SalesLine.ManufacturingPlant_CAP = d.valueStr();
            SalesLine.write();
          //  SalesLine.reread();
           // SalesLine.refresh();
         }

       
        event.CancelSuperCall();

    }

}
       
Hi,
I have written a code for a Multiselect column(ManufacturingPlant_CAP) - In data source  (Sales Line).- In Form (Sales Table).
and I want to get the value from Table(InventSite) - Column(SiteID).
But I am getting form open Like as in the picture attached and also not able to select multiple fields.

Can Anyone Suggest.

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: Multi select column in Sales Table form.

    Thanks Vignesh. It worked.

  • Verified answer
    Vignesh.A Profile Picture
    Vignesh.A 203 on at
    RE: Multi select column in Sales Table form.

    Hi Harish,

    We need to tweak the code little bit to get this achieved.

    Below is the sample code similar to your scenario.

    1. Create an extension class for the for the sales table form

    2. make CoC for the form init method

    3. Create a parm method to hold the multilookupSelectCtrl object

    pastedimage1678985367982v1.png

    4. Create an Event Handler class to take the onLookup Event of the form control where the multi select lookup is required.

    5. Write the below code to set the selected value to the field.

    pastedimage1678985532327v2.png

    Below is the result of the code.

    pastedimage1678985653048v3.png

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: Multi select column in Sales Table form.

    Thanks for the reply Vignesh.

    I have also used 'SysLookupMultiSelectCtrl' But the result is same. When I am selecting  multi records it is showing like - 0;0 (Zero for each record selected).

  • Vignesh.A Profile Picture
    Vignesh.A 203 on at
    RE: Multi select column in Sales Table form.

    Hi Harish,

    From your code, I understand that, you are opening the Invent site form through arguments during the lookup method and and try to select multiple records in it.

    But we can have a simple approach to it. Try to use "SysLookupMultiSelectCtrl" class to bring a lookup with multilple record selection options.

    There are many standard forms which uses this class to bring multi select lookup. You can find reference of this class to see how there are being used.

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,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans