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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Adding Key/Value Pair to FormComboBoxControl

(0) ShareShare
ReportReport
Posted on by 70

Dear Dynamics community,

I'm looking around on the FormComboBoxControl trying to find a property where I can pass along a key/value pair (thinking Dictionary in C#) to be able to have a locationId relate to a locationName.  The user would choose the displayed locationName but it's the locationId I'm interested in passing on to the next step in the process.

Tried the item() property but that's merely an int, not an ordered list tied to the list.  Same with containerId...

Any thoughts or ideas?  Thought perhaps the .insert() would work but the second parameter is merely an index.

public void createOriginOptions(FormComboBoxControl combo, RecId party)
    {
        var sortedList = new System.Collections.SortedList();
        combo.clear();
        combo.add(NO_FILTER);

        var mode = _manager.getMode();
        var locationRole = LogisticsLocationRole::findByName(mode);
        DirPartyLocationPrimaryAndRolesView locationRoleView;
        LogisticsLocation location;
        LogisticsPostalAddress originAddress;


        while select LocationId, Description from location
            join locationRoleView
                where location.RecId == locationRoleView.Location
            join originAddress
                where location.RecId == originAddress.Location
            && locationRoleView.Party == party
            && locationRoleView.LocationRole == locationRole.RecId
        {
            if (sortedList.ContainsValue(location.LocationId)) continue;
            sortedList.add(location.LocationId, location.Description);
        }
        
        for (int i = 0; i < sortedList.Count; i  )
        {
            combo.item(i 1);
            //combo.item(sortedList.GetKey(i));
            combo.add(sortedList.GetByIndex(i));
        }
    }

[Control("ComboBox")]
    class ShipFromOriginLocation
    {
        /// 
        ///
        /// 
        /// 
        public boolean modified()
        {
            boolean ret = super();
            int locationId = this.item();
            str originLocation = this.valueStr();
            if (originLocation != "")
            {
                _originTextSelected = originLocation;
                _locationIdSelected = locationId;
            }
    
            return ret;
        }

    }

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    That's not how these things are done in D365FO. What you should do is overriding lookup() (or lookupReference()) method and using your query there. See How to: Add a Lookup Form to a Control.

    By the way, I moved your question from the Dynamics AX Forum, because it doesn't belong there.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    As Martin mentioned, in x++ you achieve this with lookups. There are default lookups that the system creates based on table relations. And you can develop lookups with x++ to cover more complex requirements.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans