Siebel Object Interfaces Reference > Siebel Programming Tools >

A Few Notes About Siebel eScript

There are some important differences between Siebel eScript and Siebel VB.

  • Siebel eScript is case-sensitive; theApplication is different from TheApplication. Siebel VB is not case-sensitive.
  • Siebel eScript does not distinguish between subroutines (which take no arguments) and functions (which take arguments). In Siebel eScript, every method is a function, whether or not it accepts arguments; therefore, it should be followed by a pair of parentheses.

Keep these differences in mind when you read the syntax diagrams. In many instances, the only difference between the VB syntax and the eScript syntax is that the eScript syntax requires the pair of parentheses at the end. In these instances, only the VB syntax is shown; you can derive the eScript syntax by adding the parentheses.

There are also some important differences between Siebel eScript and standard ECMAscript. Most important, Siebel eScript has no user interface functions. It cannot, therefore, be used to animate or control Web pages. Second, it contains two objects that are not part of standard ECMAscript: SELib and Clib. These objects implement a variety of C-like functions for interacting with the operating and file systems, and for file I/O. For details on these and other eScript functions not covered here, read Siebel eScript Language Reference.

Declare your variables. Standard ECMAscript does not require that you declare variables. Variables are declared implicitly as soon as they are used. As a general rule, you should declare the variables used in a module before you use them. Doing so makes it easier for others to understand your code, and for you to debug the code.

Use the this object reference. The special object reference this is eScript shorthand for "the current object." You should use it 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:

if (condition)
{ ...
   return (CancelOperation)

Use the with shortcut. The with shortcut applies several methods to a single object. It reduces typing and makes the code easier to read. Instead of a series of statements such as:

var oBusComp = oBusObject.GetBusComp("Opportunity");
oBusComp.SetSearchSpec( . . .);
oBusComp.SetFieldValue("QuoteNumber", sQuoteId);
oBusComp.SetFieldValue("Account", sAccount)
. . .
sSolutionId(cSolution) = oBusComp.GetFieldValue( "Id" );
. . .

use the following:

var oBusObject = TheApplication().GetBusObject("Opportunity");
var oBusComp = oBusObject.GetBusComp("Opportunity");
with (oBusComp)
   ActivateField("Quote Number");
   SetSearchSpec( "Name", varname);

   if (FirstRecord())
      var sQuoteNum = GetFieldValue( "Quote Number");
      var sAccount = GetFieldValue( "Account");
} //end with

Make effective use of the Switch construct. Use the Switch construct to choose among any number of alternatives you require, based on the value of a single variable. This 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.

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);
   case "Revenue":
      if (newrecSw =="Y")
         newrecSw = "";
         this.SetFieldValue("Account Revenue",(FieldValue));

Destroy any objects you have created when you no longer need them. While the interpreter takes care of object cleanup, it is a best practice to write code that explicitly destroys objects when they are no longer used. Explicit destruction of Siebel objects should occur in the procedure in which they are created.

To destroy objects in Siebel eScript, set each object to null in the reverse order of creation. Destroy child objects before parent objects. For example:

var oBusObject = TheApplication().GetBusObject("Contact")
var oBusComp = oBusObject.GetBusComp("Contact")

[ Your code here ]

oBusComp = null;
oBusObject = null;

Siebel Object Interfaces Reference