Welcome to MSDN Blogs Sign in | Join | Help

East Region Microsoft CRM Blog

This Blog is focused on Microsoft CRM. It specalizes in news for CRM partners and customers, customization tools for demos and local events in the Microsoft East Region.

News

  • Welcome to the Mid-Atlantic CRM Blog, formerly owned and operated by Ben Vollmer, a CRM legend ;). My name is Chris Kahl and Ben has asked me to take over the care and feeding of this most valuable resource. Like Ben, my job is to help partners and customers with Microsoft CRM in the Eastern US. This blog is a great and searchable information source. Feel free to subscribe to the RSS feed to stay current with Dynamics CRM. Any tools discussed here are for DEMO only. You should NOT use these in a production environment unless you test them. Microsoft Support DOES NOT support these tools. Everything here is provided as-is with no warranty.
What if IF isn't cutting it? How about a switch?

So I have been playing with the IF statement for quite some time now and from time to time it fails me. Generally it fails me when I am trying to do three or more conditions. I attempted to do some nested IF statements and Jon from our developer support group steered me to the straight and narrow. :-) So don't make fun of me for my mediocre coding skills. :-)

So instead of doing an IF, how does this look for cleaner code? You can then take on as many different scenarios as you want.

var prefix = "";
switch (crmForm.all.customertypecode.SelectedText)
{
     case "Manufacturer":
               prefix="MFG";    
               break;
     case "Investor":
               prefix="INV";
               break;

     case "Press":
               prefix="SCUM";
               break;
     default:
               break;
}

 

Here is a link to the MSDN page that has a ton more details on the switch command. Enjoy!

switch Statement (JScript 5.6)

Posted: Monday, June 25, 2007 11:30 AM by Ben Vollmer
Filed under:

Comments

Jeff Dempsey said:

Thanks!

I was a big If..then user back in the days of my TRS-80 CoCo, and then, when I discovered the switch statement (in college, a few years and an IBM clone later), I was a changed man.  Clean, concise, and easy to use!

Jeff

# August 6, 2007 6:02 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker