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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

javascript set selected optionset value

(0) ShareShare
ReportReport
Posted on by 2,512

Hi, how can we set selected optionset value through javascript. For example, I have two optionsets: optionsetA, optionsetB, the selected value in optionsetB should be based on optionsetA. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     did you try Xrm.Page.getAttribute('your attribute name').setValue(12345678_your_option_set_value)?

      Also, this might be useful:

    https://msdn.microsoft.com/en-us/library/gg594433.aspx

  • ram r Profile Picture
    on at

    To set an optionset value

    Xrm.Page.getAttribute("<your optionset name>").setValue("<your option>")

    To get an optionset value

    Xrm.Page.getAttribute("<your optionset name>").getValue()

    If you are looking for dependent option sets, please refer below example

    msdn.microsoft.com/.../gg594433.aspx

    To remove an option

    Xrm.Page.getControl("<your optionset name>").removeOption("<your option>");

    To add an option

    Xrm.Page.getControl("<your optionset name>").addOption("<your option>");

    To remove all options

    Xrm.Page.getControl("<your optionset name>").clearOptions();

  • sdnd2000 Profile Picture
    2,512 on at

    Hi, Guys, that is quite helpful, but I can not do clear the optionset, and re-add it with new items? since it gaves me this error, when loading the form.

    2017_2D00_08_2D00_16_5F00_1501.png

        Xrm.Page.getControl("header_statuscode").clearOptions();
        var progress ={value:1,text:"In Progress"};
        var hold = {value:2,text:"On Hold"};
        var scheduled= {value:3,text:"Scheduled"};
        var transferred ={value:491050000,text:"Transferred"};
        Xrm.Page.getControl("header_statuscode").addOption(transferred);
        Xrm.Page.getControl("header_statuscode").addOption(progress);
        Xrm.Page.getControl("header_statuscode").addOption(hold);
        Xrm.Page.getControl("header_statuscode").addOption(scheduled);  
        Xrm.Page.getAttribute("header_statuscode").setValue(2);


  • Verified answer
    ram r Profile Picture
    on at

    On getAttribute the field name should be statuscode and not header_statuscode

  • sdnd2000 Profile Picture
    2,512 on at

    I think that is to access to the header fields, it worked in other lines.

  • ashlega Profile Picture
    34,477 on at

    You need "header" when accessing controls, not when accessing the attributes

  • sdnd2000 Profile Picture
    2,512 on at

    Thanks. I changed that, but the status reason optionset had no value selected.

  • sdnd2000 Profile Picture
    2,512 on at

    I still got empty selected status reason

    5722.2017_2D00_08_2D00_16_5F00_1501.png

  • ashlega Profile Picture
    34,477 on at

    Do you see them in the list when you click on the status reason field?

  • ram r Profile Picture
    on at

    A quick question,

    do you have these options in optionset or you are adding new options that does not exist in optionset?

    Are the newly added options visible in optionset?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans