Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics 365 - Multi-Select fields using JavaScript

Posted on by 460

Hi,

How can I get the Value from an Item in the Multiselect field using JavaScript

data in multi-select field :

Item        Value
-----        --------------

Pear         1000000001
Orange    1000000002
Apple       1000000000

So now I want to get the value for Pear  =  100000001
logic:  Get (Value)  where  Item = Pear

There may be up to 30 items in my list to go through

The .getValue returns all values separated by a comma  --> 100000000, 100000001, 100000002 
The .getText   returns all texts separated by a comma     --> Apple, Pear, Orange

Any help is greatly appreciated.

*This post is locked for comments

  • nickmangioros Profile Picture
    nickmangioros 460 on at
    RE: Dynamics 365 - Multi-Select fields using JavaScript

    Him,

    Yes thanks,

    I am aware hat the getValue returns the following array  --> (100000000, 100000001, 100000002)

    But I need to know

    - the value for which Pear belongs to and store it in a variable

    - the index for which Pear belongs to and store it in a variable

    so I can manipulate it later below

    Here is what I am doing:

    var = currentFruit = "Pear";

    Pear is in the array but I do not know its value

    so what I need is to get the value for it from the array.

    var resultValue = getValue where .getText = Pear

    Hope this is clear.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dynamics 365 - Multi-Select fields using JavaScript

    Hello,

    getValue is the way to go and it should return array of ints and not concatenated ints. Check following article - www.itaintboring.com/.../dynamics-365-v9-multi-select-option-set

  • Suggested answer
    - Matt Bayes - Profile Picture
    - Matt Bayes - 890 on at
    RE: Dynamics 365 - Multi-Select fields using JavaScript

    Hey Nick,

    We have created a generic function that allows us to retrieve all of the items of a Multi-Select Option Set. This function is then called in our form javascript and then filtered to our specific value.

    GENERIC FUNCTION:

    GetMultiSelectOptions = function (formContext, field) {
        try {
            var optionField = formContext.getAttribute(field);
    
            if (optionField !== null) {
                var options = optionField.getSelectedOption();
    
                return options;
            }
        }
        catch (e) { alert("Error retrieving Multi-Select options for " + field); }
    };


    FORM CODE:

    var options = GetMultiSelectOptions(formContext, "bdo_accountsubtype");
    
                if (options !== null) {
                    if (options.filter(i => i.value === 755390007).length > 0) {        
                        SetTabVisibility(formContext, "tab_17_brand", true);
                    }
    
    
                    if (options.filter(i => i.value === 755390005).length > 0) {        
                        SetTabVisibility(formContext, "tab_19_owner", true);
                    }
                }


    The form code calls our generic function, retrieving the values of our passed in option set. The "formContext" parameter should be used since this is the best practice for V9.X of Dynamics 365.

    The options are then filtered based on the value we want, and in my case, we set the visibility of a tab if the option is found.

    If you have any questions please let me know!

    Matt Bayes

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans