Siebel eScript Language Reference > Siebel eScript Language Overview >

Siebel eScript Programming Guidelines


If you have never programmed in JavaScript before, you should start with a general-purpose JavaScript reference manual. You need to understand how JavaScript handles objects before you can program using the Siebel eScript.

Declare your variables. Standard ECMAScript does not require that you declare variables. Variables are declared implicitly as soon as they are used. However, Siebel eScript requires you to declare variables with the var keyword. Declare variables used in a module before you use them, because this declaration makes it easier for others to understand your code and for you to debug the code. The only exception to this standard is declaring a variable inside a loop controller, which restricts the scope of that reference to the loop. Local declaration prevents the accumulation of unwanted values.

Consider case sensitivity. Be aware that Siebel eScript is case sensitive. Therefore, if you instantiate an object using the variable name SiebelApp, for example, eScript does not find that object if the code references it as siebelapp or SIEBELAPP instead of SiebelApp. Case sensitivity also applies to method names and other parts of Siebel eScript.

Use parentheses () with functions. Siebel eScript functions, like those in standard JavaScript, require trailing parentheses () even when they have no parameters.

Use four-digit years in dates. Siebel applications and the ECMA-262 Standard handle two-digit years differently. Siebel applications assume that a two-digit year refers to the appropriate year between 1950 and 2049. The ECMA-262 Standard assumes that a two-digit year refers to a year between 1900 and 1999, inclusive. If your scripts do not enforce four-digit date entry and use four-digit dates, your users may unintentionally enter the wrong century when performing a query or creating or updating a record.

(BusComp) methods GetFormattedFieldValue() and SetFormattedFieldValue() are examples of Y2K sensitivities in Siebel eScript that use two-digit dates. If you use these methods in a script, users requesting orders for the years from 03 to 05 may find that they have incorrectly retrieved orders for the years 1903-1905 (probably an empty list), instead of for 2003-2005, as they had wanted.

If you use only four-digit dates in your programs, you will not have Y2K problems with your scripts. With the preceding example, you could use GetFieldValue() and SetFieldValue(), which require dates to be specified using the canonical Siebel format (MM/DD/YYYY), instead of GetFormattedFieldValue() and SetFormattedFieldValue().

Use the this object reference. The special object reference this is eScript shorthand for "the current object." You should use this in place of references to active business objects and components. For example, in a business component event handler, you should use this in place of ActiveBusComp, as shown in the following example:

function BusComp_PreQuery ()
{
   this.ActivateField("Account");
   this.ActivateField("Account Location");
   this.ClearToQuery();
   this.SetSortSpec( "Account(DESCENDING)," +
      " Account Location(DESCENDING)");
   this.ExecuteQuery();

   return (ContinueOperation);
}

Make effective use of the switch construct. The switch construct directs the program to choose among any number of alternatives you require, based on the value of a single variable. This alternative is greatly preferable to a series of nested If statements because it simplifies code maintenance. It also improves performance, because the variable must be evaluated only once.

Siebel eScript Language Reference Copyright © 2007, Oracle. All rights reserved.