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 :
Customer experience | Sales, Customer Insights,...
Answered

Best way to display Description of Value in Option Set

(0) ShareShare
ReportReport
Posted on by 45

Hello,

I have an Option Set and would like a tooltip or description / information bar to be displayed containing the description of the value the user has chosen.

What would be the best/recommended way to achieve this?

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi e0209,

    You could set a form notification bar in each time of onChange event of Option Set field.(Clear previous notification bar at beginning)

    function onChangeOfOptionSet1() {
      // Clear notification bar
      formContext.ui.clearFormNotification();
      // Set notification bar
      var option = formContext.getAttribute('preferredcontactmethodcode').getSelectedOption().text;
      if (option === 'Email') {
        formContext.ui.setFormNotification("Send email to contact with Outlook", 'INFO')
      } else if (option === 'Phone') {
        formContext.ui.setFormNotification("Keep in touch with contact.", 'INFO')
      }
    }

    When the option is "Email":

    pastedimage1591256106129v1.png

    When the option is "Phone":

    pastedimage1591256149687v2.png

    Regards,

    Clofly

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi e0209,

    You could change the name of the value so that the purpose of the value is clear. Alternatively, add a description to the option set field itself to indicate what the field is used for and explain each value.

  • e0209 Profile Picture
    45 on at

    Thanks Clofly, is there any way to pull the text in the notification from the Description of the Value in the Option set instead of hardcoding it into the script?

  • e0209 Profile Picture
    45 on at

    Thanks Adrian,

    How do you propose that the end user see the description of the option set when selecting a certain option?

    It appears to me the description is only visible in the customization backend area.

    The values are provided by business so we can't change them and it will take quite a number of words to make it clear which will be too long for the field in practical terms.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi e0209,

    Yes, we can also get description of a selected option by retrieving metadata of a specific optionset field of a specific entity.

    e.g: The code below will retrieve description of the value of "Preferred Method of Contact" option set of Contact entity.(We still fire the function at the field onChange event.)

    function onChangeOfOptionSet(executionContext) {
    
        var formContext = executionContext.getFormContext();
        // Clear notification bar
        formContext.ui.clearFormNotification();
        // Set notification bar
        var option = formContext.getAttribute('preferredcontactmethodcode').getSelectedOption().text;
    
        var req = new XMLHttpRequest();
        req.open("GET", formContext.context.getClientUrl()   "/api/data/v9.1/EntityDefinitions(LogicalName='contact')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq 'preferredcontactmethodcode'&$expand=OptionSet", true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var results = JSON.parse(this.response);
                    for (var i = 0; i < results.value[0].OptionSet.Options.length; i  ) {                   
                        var Label = results.value[0].OptionSet.Options[i].Label.UserLocalizedLabel.Label;
                        if (option === Label) {
                            formContext.ui.setFormNotification(results.value[0].OptionSet.Options[i].Description.UserLocalizedLabel.Label, 'INFO');
                        }
                    }
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
        
    }

    Let's test code above:

    Description value of Any, Email and Phone

    pastedimage1591337951745v1.png

    pastedimage1591337967937v2.png

    pastedimage1591337984463v3.png

    Result:

    pastedimage1591338073114v4.png

    pastedimage1591338092053v5.png

    pastedimage1591338117062v6.png

    If no option is selected or if there is description for selected option, then notification bar won't appear.

    Regards,

    Clofly

  • e0209 Profile Picture
    45 on at

    Thank you very much Clofly.

    Works like a charm!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans