web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Lookup not working

(0) ShareShare
ReportReport
Posted on by 1,947
Hi,

if i add VendAccount as a multi-select lookup on a custom form
 
1. should add i add code to init method or lookup method?
[ExtensionOf(formStr(Form1))]
final class Form1_Extension
{


    public void init()
    {
        next init();

        SysLookupMultiSelectCtrl multiSelectCtrl;
		
        Query query = new Query();
        QueryBuildDataSource qbds = query.addDataSource(tableNum(VendTable));
        qbds.addSelectionField(fieldnum(VendTable,VendAccount));

        multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(this, Form1_Vendor, query, false);  

    }

}

OR


class Form1_EventHandler
{
    
    [FormControlEventHandler(formControlStr(Form1, Form1_Vendor), FormControlEventType::Lookup)]
    public static void Form1_Vendor_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormStringControl vendor = sender.formRun().design().controlName(formControlStr(Form1, Form1_Vendor)) as FormStringControl;

        SysLookupMultiSelectCtrl multiSelectCtrl;
		
        Query query = new Query();
        QueryBuildDataSource qbds = query.addDataSource(tableNum(VendTable));
        qbds.addSelectionField(fieldnum(VendTable,VendAccount));

        multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false);

    }

}

2. using both ways, the lookup works but  when i select multiple values, the control doesn't show them, it stays empty. I read i need to use set, but didn't understand how to use it, can u show me and explain please?
i can see examples on dialogs where they don't use set
Categories:
I have the same question (0)
  • Suggested answer
    Priya_Kadu Profile Picture
    80 on at
    Lookup not working
    Hello, 
     
    Please try this code :
     
    [ExtensionOf(formStr(Form1))]
    final class Form1_Extension
    {
        SysLookupMultiSelectCtrl multiSelectCtrl_Vendor;
        Set                     vendorSet;        // stores selected accounts

        public void init()
        {
            next init();
            vendorSet = new Set(Types::String);   
            // Build lookup query
            Query query = new Query();
            QueryBuildDataSource qbds = query.addDataSource(tableNum(VendTable));
            qbds.addSelectionField(fieldNum(VendTable, VendAccount));
            // Create the multi-select lookup control
            multiSelectCtrl_Vendor = SysLookupMultiSelectCtrl::constructWithQuery(
                                        this,
                                        Form1_Vendor,
                                        query,
                                        false);
                    if (vendorSet.elements() > 0)
            {
                multiSelectCtrl_Vendor.set(vendorSet);
                Form1_Vendor.text(this.setToString(vendorSet));
            }
        }

        // Called when user selects values in the lookup
        public boolean Form1_Vendor_modified()
        {
            boolean ret = next Form1_Vendor_modified();
            vendorSet = multiSelectCtrl_Vendor.get();
            Form1_Vendor.text(this.setToString(vendorSet));
            return ret;
        }

        // Helper method — convert Set to comma-separated string
        private str setToString(Set _set)
        {
            str result = "";
            SetEnumerator setEnum = _set.getEnumerator();
            while (setEnum.moveNext())
            {
                result += (result == "" ? "" : ", ") + setEnum.current();
            }
            return result;
        }
    }
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 758 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 607 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 402 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans