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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Display a <select> by retrieving option set in a web resource

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm new on Dynamics 365, and I still don't succeed in retrieving my option set text/values.

I would like display the options by using a web resource searching in an option set the options available. 

But after some work, I still don't succeed. 


<html><body>

<select multiple id="selectForm">
</select>
</body></html>

<script>
var attribute = Xrm.Page.getAttribute('new_optionset_prenom'); var optiontable = attribute.getOptions(); var i = 0; for (i in optiontable)
{ document.getElementById("selectForm").options[document.getElementById("selectForm").options.length] =
new Option(optiontable[i], i);

}
</script>

I imagined that optiontable was a table of object for every option, but I don't succeed in manipulate it.

In the end I would like to get an exemple like that : 

azertyuiop.PNG

because my option set has some name inside.

thank you for your help !

regards

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Display a <select> by retrieving option set in a web resource

    Hi,

    You try writing a javascript function in the script and call this function on the load of the body of the HTML web resource as shown below.

    <script>
     function onBodyLoad(){
       debugger;
       var optionsetLabel = vals[0];
       console.log('optionSet name :', optionsetLabel);
       //champ CRM
       var fieldcrm = vals[1];
       console.log('field of the crm :', fieldcrm);	
    
       var attribute = window.parent.Xrm.Page.getAttribute(optionsetLabel);
       var optiontable = attribute.getOptions();
       var dropdown = document.getElementById("selectForm");
    
       var i = 0;
       for (i in optiontable) {
          var text = optiontable[i].text;
          var value = optiontable[i].value;
          var option = document.createElement("option");
          option.text = text;
          option.value=value; // or you can set i instead if you want
          dropdown.add(option);
       }
     }
    </script>
    
    <body onload = "onBodyLoad()" >
        <select multiple id="selectForm">
        </select>
    </body>

    You could now try debugging the code using developer tools.

    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: Display a <select> by retrieving option set in a web resource

    Thank your for your help !

    Unfortunately, didn't succeed in retrieving the options.

    I really don't know what is the problem. I'm using a web resource html and the "console.log(arg); " even doesn't appear in the console part of F12. I think this is because of the web resource html. So the browser doesn't access to those variable.

    here is my code in the web resource html : 

    <script>
       var optionsetLabel = vals[0];
       console.log('optionSet name :', optionsetLabel);
       //champ CRM
       var fieldcrm = vals[1];
       console.log('field of the crm :', fieldcrm);	
    
       var attribute = window.parent.Xrm.Page.getAttribute(optionsetLabel);
       var optiontable = attribute.getOptions();
       var dropdown = document.getElementById("selectForm");
    
       var i = 0;
       for (i in optiontable) {
          var text = optiontable[i].text;
          var value = optiontable[i].value;
          var option = document.createElement("option");
          option.text = text;
          option.value=value; // or you can set i instead if you want
          dropdown.add(option);
       }
    </script>
    
    <body>
        <select multiple id="selectForm">
        </select>
    </body>
    


  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Display a <select> by retrieving option set in a web resource

    Hi,

    If you are using this javascript inside an HTML web resource, it should be as follows.

    var attribute = window.parent.Xrm.Page.getAttribute('new_optionset_prenom');

    Hope this helps.

  • Verified answer
    SCV Profile Picture
    1,004 on at
    RE: Display a <select> by retrieving option set in a web resource

    Hi,

    Since you are inside a web resource you will have to use the word parent like below: 

    var attribute = parent.Xrm.Page.getAttribute('new_optionset_prenom');

      

    Then modify the code like below:

     

    var attribute = Xrm.Page.getAttribute('new_customerseverity');
    
    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; // or you can set i instead if you want
    
         dropdown.add(option);
    
    }
    

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans