Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

JavaScript to show/hide section based on option set selection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have the following JavaScript to show/hide sections in a tab based on the option set selection and I'm getting three errors when loading the form and when trying to change the option set selection. Can anyone please help me determine where I'm going wrong? I have applied the event as an On Change to the option set field. 

Thank you very much 

function HideOrShowSectionBasedOnoptionSetValue(){
 var value = Xrm.Page.getAttribute("new_testrequesttype").getValue();
 if(value!=null){
  if(value == 100000000){
    Xrm.Page.ui.tabs.get("Test Request").sections.get("Lab Test Request").setVisible(true);  //Shows section 1
    Xrm.Page.ui.tabs.get("Test Request").sections.get("Application Test Request").setVisible(false);  //Hides section 2
 
}
  else if(value == 100000001){
    Xrm.Page.ui.tabs.get("Test Request").sections.get("Lab Test Request").setVisible(false);  //Hides section 1
    Xrm.Page.ui.tabs.get("Test Request").sections.get("Application Test Request").setVisible(true);  //Shows section 2
 }

On form load: 

Error 1: 

Script Error

One of the scripts for this record has caused an error. For more details, download the log file.
ReferenceError: 'ShowHideTestTabs' is not defined at eval code (eval code:1:1)

Error 2: 

Script Error

One of the scripts for this record has caused an error. For more details, download the log file.
TypeError: Unable to get property 'Initialize' of undefined or null reference at eval code (eval code:1:1)

When the option set selection is changed: 

Error 3: 

Script Error

One of the scripts for this record has caused an error. For more details, download the log file.
SyntaxError: Expected ';' at RunHandlerInternal 

*This post is locked for comments

  • Verified answer
    gdas Profile Picture
    gdas 50,087 on at
    RE: JavaScript to show/hide section based on option set selection

    Hi,

    Error 1:

    ShowHideTestTabs is undefined so I can not see any such keywords in your code so this is coming from another function.

    Error 2:

    Andrew already suggested that last closing bracket is missing and that's why function is not getting in on change. Seems due to that you are getting error 3.

    Error 3:

    Same reason of error 2.

    Check your section "Name" by double clicking section property and put the correct name.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: JavaScript to show/hide section based on option set selection

    Martha,

    Inside both tabs and sections properties you can find "Name" and "Label". You should use value from "Name" field in your scripts. I believe you used value from "Label" because value in "Name" can't contain spaces.

    Also it seems that you missed one closing curly bracket - }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans