Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Multi select on dialog...
Finance forum
Suggested answer

Multi select on dialog field

Posted on by 465

Hi,

So i'm trying to do multi select on dialog field. Below is what i did. The multi- select is working, and i can see that i filled 2 invoices for example but when I pass the contract to the service class, i can see the dialog has Invoice1 but Invoice2 is corrupted so if it's name was CIV-000001 I see it in the debug as CIV

Also i noticed that addLookupField is not working, it gives me all fields not only the ones i specified.

Here's what i did:

public void postRun()
{
    super();
    
    register overrides for form control events
    field1.registerOverrideMethod(methodstr(FormStringControl, Lookup),
        methodstr(InvoiceUIBuilder, lookUpfield1), this);
}

    public void lookUpfield1(FormStringControl _control)
    {
        SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(CustInvoiceJour), _control);
        Query               query           = new Query ();
        query.addDataSource(tableNum(CustInvoiceJour)).addRange(fieldNum(CustInvoiceJour, flag)).value(enum2Str(NoYes::No));
        // Add fields
        sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour, InvoiceId));
        sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour, InvoiceDate));


        container con;
        SysLookupMultiSelectGrid::lookup(query,_control,_control,_control,con);

        // Run lookup
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();

    }

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Multi select on dialog field

    any idea?

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Multi select on dialog field

    Here's the full code of the UI builder

        DialogField field1;
    
        public void postBuild()
        {
            super();
        
            // get references to dialog controls after creation
            field1 = this.bindInfo().getDialogField(this.dataContractObject(),
                                        methodStr(Contract, parmInvoiceId));
    
        }
    
        public void postRun()
        {
          super();
        
          register overrides for form control events
          field1.registerOverrideMethod(methodstr(FormStringControl, Lookup),
             methodstr(InvoiceUIBuilder, lookUpfield1), this);
        }
    
        public void lookUpfield1(FormStringControl _control)
        {
            SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(CustInvoiceJour), _control);
            Query               query           = new Query ();
            query.addDataSource(tableNum(CustInvoiceJour)).addRange(fieldNum(CustInvoiceJour, flag)).value(enum2Str(NoYes::No));
            // Add fields
            sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour, InvoiceId));
            sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour, InvoiceDate));
    
    
            container con;
            SysLookupMultiSelectGrid::lookup(query,_control,_control,_control,con);
    
            // Run lookup
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
    
        }

    and in the contract  i used custInvoiceId.

    i don't think query filter will work in my scenario, i'm still investigating this but for now i need a solution to this problem

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Multi select on dialog field

    Could you share your full code? From the code that you shared, we don't see how the dialog field (field1) is created so it's not possible to spot if there's something that you could do differently.

    I still strongly suggest using the standard query approach which is familiar to users, works similarly across the system and doesn't require any development.

  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Multi select on dialog field

    I don't think you should be overriding lookup() method at all. Call SysLookupMultiSelectCtrl::constructWithQuery() from postRun(). You'll find plenty of examples in the standard application (by using "Find references").

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Multi select on dialog field

    Hi Nikolaos,

    i showed u in the code above the i used registerOverrideMethod for the lookup, but the multi select is getting corrupted... so is there a solution for this issue using this approach?

    and why the add lookupField is not working? it's returning all fields instead of the ones i specified?

  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Multi select on dialog field

    For reference, we also discussed using a query in other threads using values coming from multiselect of a dialog and adding a new table to an existing data entity.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Multi select on dialog field

    I guess there is. Just override the lookup method of the field, then the lookup works in any way you define, regardless of EDT of the field.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Multi select on dialog field

    ok, i will try to see if the query approach will work for me. But for now, is there a way i can make it fit for all invoices?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Multi select on dialog field

    I think you should use the out of the box query dialog. That's used everywhere in the system so your users must be trained to get familiar with it. Yes, if multiple values are selected, your user must type comma in between the values.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Multi select on dialog field

    I used CustInvoiceId in the contract, so i should use Notes EDT but the lookup will disappear that way , what should i use instead?

    u mean i should use query filter instead of contract parameter?

    i noticed that in query filter when u multi select things don't get separated by a comma so if i'm going to select alot of data this might get frustrating, is there a solution to this?

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans