Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to get Property 'removeOption'

Posted on by 2,645

Hello, I am having an issue with my below script and wondering if someone can help me out.  I tried F12, but that isn't giving me an error.

function RecordTypeOnChange()
{
var RecordType = Xrm.Page.getAttribute("nhs_recordtype").getText();
var RequestType = Xrm.Page.getAttribute("nhs_requesttype").getText();

if (RecordType == null || RecordType =='undefined' || RecordType =='')
{

}
else if (RecordType != null && RecordType != 'undefined' && RecordType !='')
{
if (RecordType == "Medicare")
 {
  Xrm.Page.getControl("RequestType").removeOption(127130000);
  Xrm.Page.getControl("RequestType").removeOption(127130001);
  Xrm.Page.getControl("RequestType").removeOption(127130003);
  Xrm.Page.getControl("nhs_idcardbooktype").setVisible(false);
 }
else if (RecordType == "Commercial")
 {
 //Xrm.Page.getControl("RequestType").clearOptions();
 Xrm.Page.getControl("RequestType").addOption({value: 127130000, text: 'Football'});
 Xrm.Page.getControl("RequestType").addOption({value: 127130001, text: 'NFL'});
 Xrm.Page.getControl("RequestType").addOption({value: 127130002, text: 'NHL'});
 Xrm.Page.getControl("RequestType").addOption({value: 127130003, text: 'NBA'});
 Xrm.Page.getControl("RequestType").addOption({value: 127130004, text: 'TBD'});
}
}
}

/**************************************************************
Function to call on Load
**************************************************************/
function RecordTypeOnLoad()
{
RecordTypeOnChange();
}

*This post is locked for comments

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Unable to get Property 'removeOption'

    Probably more than just a line

    msdn.microsoft.com/.../gg328489.aspx

    Would be something like this:

    function sectionSetNull(tab, section) {

       var section = Xrm.Page.ui.tabs.get(tab).sections.get(section);

       var controls = section.controls.get();

       var controlsLength= controls.length;

       for (var i = 0; i < controlsLength; i++) {

           controls[i].getAttribute().setValue(null);

       }

    }

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Unable to get Property 'removeOption'

    Great, thank you.  What is the line to clear out the fields when I hide an entire tab or tab and section?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Unable to get Property 'removeOption'

    point being, RequestType is not a proper control name.. Use nhs_requesttype instead.. that code you just posted seems to be ok.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Unable to get Property 'removeOption'

    I need to turn this around and clear the nhs_requesttype field each time RecordType field is changed and then readd in the appropriate options.  Would I just do the below?

    Xrm.Page.getControl("nhs_requesttype").clearOptions();

    Xrm.Page.getControl("nhs_requesttype").addOption({

                  value: 127130000,

                  text: 'Football'

              });

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Unable to get Property 'removeOption'

    Hi,

     are you sure "RequestType" is the right name? Shoud it be "nhs_requesttype"?

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Unable to get Property 'removeOption'

    Hello,

    Try to use nhs_requesttype instead of RequestType in places where you work with controls like:

    function RecordTypeOnChange() {

       var RecordType = Xrm.Page.getAttribute("nhs_recordtype").getText();

       var RequestType = Xrm.Page.getAttribute("nhs_requesttype").getText();

       if (RecordType == null || RecordType == 'undefined' || RecordType == '') {} else if (RecordType != null && RecordType != 'undefined' && RecordType != '') {

           if (RecordType == "Medicare") {

               Xrm.Page.getControl("nhs_requesttype").removeOption(127130000);

               Xrm.Page.getControl("nhs_requesttype").removeOption(127130001);

               Xrm.Page.getControl("nhs_requesttype").removeOption(127130003);

               Xrm.Page.getControl("nhs_idcardbooktype").setVisible(false);

           } else if (RecordType == "Commercial") {

               //Xrm.Page.getControl("RequestType").clearOptions();

               Xrm.Page.getControl("nhs_requesttype").addOption({

                   value: 127130000,

                   text: 'Football'

               });

               Xrm.Page.getControl("nhs_requesttype").addOption({

                   value: 127130001,

                   text: 'NFL'

               });

               Xrm.Page.getControl("nhs_requesttype").addOption({

                   value: 127130002,

                   text: 'NHL'

               });

               Xrm.Page.getControl("nhs_requesttype").addOption({

                   value: 127130003,

                   text: 'NBA'

               });

               Xrm.Page.getControl("nhs_requesttype").addOption({

                   value: 127130004,

                   text: 'TBD'

               });

           }

       }

    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans