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)

javascript set selected optionset value

(0) ShareShare
ReportReport
Posted on by 2,510

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,510 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,510 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,510 on at

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

  • sdnd2000 Profile Picture
    2,510 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

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