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)

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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    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

  • Community Member Profile Picture
    on at

    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
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

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

  • ashlega Profile Picture
    34,477 on at

    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)

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