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?
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?
Thank you very much Clofly.
Works like a charm!
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
Result:
If no option is selected or if there is description for selected option, then notification bar won't appear.
Regards,
Clofly
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.
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?
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.
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":
When the option is "Phone":
Regards,
Clofly
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156