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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to get Property 'removeOption'

(0) ShareShare
ReportReport
Posted on by 26

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

I have the same question (0)
  • Verified answer
    ashlega Profile Picture
    34,477 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
    26 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
    34,477 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
    26 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
    34,477 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
    84,331 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans