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 to show/hide section based on option set selection

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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 - }

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

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