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 optionsetvalue

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I posted similar query yesterday, but it did not seem to work. Basically, I have populated the values in the optionset already. Now I want to filter it out based on another optionset value, I tried the below code, every time I cleared the optionset and re-added the optionset values, then set the selected value, but I can see the list, while it did not get selected. now I am stuck on this.

    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("statuscode").setValue(2);


 

*This post is locked for comments

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

    Hi sdnd,

     try this:

       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);

       setTimeout(function(){

           Xrm.Page.getAttribute("statuscode").setValue(2);

       }, 100);

  • sdnd2000 Profile Picture
    2,510 on at

    It seems working, but it is relevant to the loading time frame?

  • ashlega Profile Picture
    34,477 on at

    I don't know.. it seems you have to give that field some time to initialize.

    Actually, I don't think it's relevant to the loading timeframe. You can probably lower that 100 to 10 and it will still work.

    When you modify the set of options in the control and set selected option right away, what may happen is that attribute and control options are somewhat out of sync yet (not all of the internal event handlers may have been fired - you are still on the same thread, so they may be waiting till that thread has finished).

  • Suggested answer
    Friyank Profile Picture
    944 on at

    You can use business rule to set default value

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