CRM 2011 – Javascript case statement

I had to write some code where I had a lot of checkboxes and when a user selected a value on a dropdown then some would be shown and the rest would be hidden.

To do this I created 6 sections and placed the checkboxes in the correct section.  When the user changed the dropdown I then displayed one of the sections and hide the others.  This saved me writing the visible functionality for all the checkboxes (and there were loads – 60 plus).

Below is the Javascript which first reads the drop down and then based on the value it then displays a section and hides another.  The real code had 6 sections which is why I used a switch statement rather than lots of IF and IFElse statements.

var mainJobType = Xrm.Page.getAttribute("meta_generaljobtype").getText();

 switch (mainJobType) {
 case "Internal Works":
 case "External Works":



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.