Avoid Nested If Statements

To avoid a nested If statement, you can use one of the following statements:

  • In Siebel VB, use the Select Case statement

  • In Siebel eScript, use the Switch statement

Each of these statements chooses from multiple alternatives according to the value of a single variable. It is recommended that you use the Select Case statement instead of a series of nested If statements. It simplifies code maintenance and improves performance. Siebel CRM evaluates the variable only once.

The following is an example use of the Switch statement:

switch (FieldName)
{
   case "Status":
   {
      var sysdate = new Date();
      var sysdatestring = ((sysdate.getMonth() + 1) + "/" + sysdate.getDate() + 
         "/" + sysdate.getFullYear()+ " "+ sysdate.getHours() + ":" +
         sysdate.getMinutes()+":" + sysdate.getSeconds());
      this.SetFieldValue("Sales Stage Date",sysdatestring);
      if ((FieldValue) == "Not Attempted")
      {
         if (this.GetFieldValue("Primary Revenue Amount") > 0)
         this.SetFieldValue("Primary Revenue Amount",0);
      }
      break;
   }
   case "Revenue":
   {
      if (newrecSw =="Y")
      {
         newrecSw = "";
         this.SetFieldValue("Account Revenue",(FieldValue));
      }
      break;
   }
}