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 :
Microsoft Dynamics CRM (Archived)

How to display data from option set into a dropdown.

(0) ShareShare
ReportReport
Posted on by

Hello Everyone.

I am facing an issue in displaying a data in a drop-down based on selection from an 

option set.

I have a Sample as a Custom Entity.

In Sample Entity there is a field name is Cars which have multiple cars in an option set data type.

As I select Cars from options set it should display in a drop-down.

The code is displayed below:-

<html>
<head>
<title> MultiSelection Demo </title>
</head>
<body>
<select multiple id="selectForm">

</select>
</body>
</html>
<script>
var attribute = window.parent.Xrm.Page.getAttribute('smp_optionset');
var optiontable = attribute.getOptions();
var dropdown = document.getElementById("selectForm");
for(var i=0; i<optiontable.length; i++)
{
var text = optiontable[i].text;
var value = optiontable[i].value;

var option = document.createElement("option");
option.text = Text;
option.value = Value;
dropdown.add(option);

alert("Text = " + text + "Value = " + value );

</script>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    what CRM version you working with?

  • Community Member Profile Picture
    on at

    Its an trial version.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Ajay Walmiki,

    what type of error you get?

    Have you tried to debug code?

    Please help us to understand better.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    The code that you have above will just populate the drop down from the web page with the values from the optionset.

    From my understanding of your requirements, what you are looking for in to capture the change event of the optionset and change the value accordingly in the web page (i.e. HTML Web Resource).

    In order to accomplish this, you need to add an OnChange event to your optionset, and in the JavaScript of that event, call a function on the HTML Web Resource, and pass the value of the newly changed optionset item. You can then add code to change the value in your drop down list.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi!

    I think you should you write dropdown.appenChild (option); instead of dropdown.add (option) ;,

    Please note that code will substitute all the values at once.

    If your purpose is the current / selected, you should get the current value - window.parent.Xrm.Page.getAttribute ("smp_optionset"). GetValue () ;, and in a loop to get the text of the current value you should substitute it in dropdown. 

    Hope it helps

    Please mark it As Answered or Verified if it did help you.

    Thanks

    Vlad

    http://dynamicalabs.com/

  • Community Member Profile Picture
    on at

    Its not working at all.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans