Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving option set values in a web resource

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm working on Dynamics 365 and I've created a web resource. 

In this web resource in JS, I would like to pass a parameter which is the name of an option set. By this way just by changing the name of the parameter, you will be able to retrieve the option set values of an other option set. In the end Changing the parameter make change the text.

I already know how to get the parameter for stocking the name of the option set in the web ressource.

I really don't know how to proceed, I'm a student learning about crm and a lot of things are new for me. That's why I would appreciate your help to indicate me how should I proceed, and how to do that.

thanks a lot.

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Retrieving option set values in a web resource

    Hi Carnatik,

     are you getting any errors in your code? What is that optionsetLabel - is it a variable defined somewhere? Basically, if the name of your attribute were "new_optionsetattributename", that line would look like this:

     var OptionSetName = Xrm.Page.getAttribute("new_optionsetattributename").getOptions();

     Xrm vs window.parent.Xrm: it depends on what you are doing. Originally, I thought you are using an HTML web resource, in which case you have to use window.parent.Xrm (since Xrm is not defined directlty in the web resource iframe - it's defined in the parent). If, on the other hand, it's a javascript web resoure then no, you don't need to use "window.parent"

     As for the XMLHttpRequest - you have to use it if you need your script to talk to the server (that's for WebAPI, for example)

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Retrieving option set values in a web resource

    Hi,

    Instead of OptionSetName.getOptions().length, use just OptionSetName.length. Also replace Xrm with window.parent.Xrm.

  • RE: Retrieving option set values in a web resource

    Thank you for your response.

    So I imagined somthing like :

    function getOptionsetLabel()
    
    {
    
    var OptionSetName = Xrm.Page.getAttribute(optionsetLabel).getOptions();
    
    for(var intCounter=0; intCounter < OptionSetName.getOptions().length; intCounter++)
    
      {
    
    var backendtext=OptionSetControl.getOptions()[intCounter].text;
    
    var select = document.getElementById("selectForm");
    
    select.options[select.options.length] = new Option(backendtext);
    
    }
    
    }
    


    my option set name is stored in "optionsetLabel" am I right ? because this code is not working as i would like.

    - I don't understand your "window.parent.xrm" shoud I remplace "xrm" by "window.arent.xrm" ?

    - Other question : I never use "XMLHttpRequest" in my code. Am I obliged to use it ?

    thanks a lot !

    reguards

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Retrieving option set values in a web resource

    Hi Carnatik,

     as Andrii mentioned, you can use WebAPI to work with the metadata.

     But you can also work with the Xrm.Page model - for example, if you have a web resource and if you wanted to get all the options for a particular option set which has been added to the form, you can access that option set through Xrm.Page

     In the web resource, it will likely be

     window.parent.Xrm

     rather than just Xrm.. but, in the end, there is a bunch of methods you can use, including getOptions:

    msdn.microsoft.com/.../gg334409.aspx

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Retrieving option set values in a web resource

    Hello,

    I believe you should check how to retrieve metadata using WebApi - msdn.microsoft.com/.../mt607833.aspx

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans