Siebel Object Interfaces Reference > Siebel Programming Tools >

A Few Notes About Siebel eScript


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

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 the eScript Language Reference topics within Siebel Tools Online Help.

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. As a general rule, 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. There is one notable exception to this standard. Declaring a variable inside a loop controller restricts the scope of that reference to within the loop. This prevents the variable from persisting; it can therefore be declared again inside another loop.

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.

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

   return (ContinueOperation);
}

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

var oBusComp = oBusObject.GetBusComp("Opportunity");
oBusComp.ClearToQuery();
oBusComp.SetSearchSpec( . . .);
oBusComp.ExecuteQuery(ForwardBackward)
oBusComp.FirstRecord();
oBusComp.NewRecord(NewAfter);
oBusComp.SetFieldValue("QuoteNumber", sQuoteId);
oBusComp.SetFieldValue("Account", sAccount)
. . .
sSolutionId(cSolution) = oBusComp.GetFieldValue( "Id" );
. . .

use the following:

var oBusComp = oBusObject.GetBusComp("Opportunity");
with oBusComp
{
   ClearToQuery();
   SetSearchSpec( . . .);
   ExecuteQuery(ForwardBackward)
   FirstRecord();
   NewRecord(NewAfter);
   SetFieldValue("QuoteNumber", sQuoteId);
   SetFieldValue("Account", sAccount)
}
. . .
sSolutionId(cSolution) = oBusComp.GetFieldValue( "Id" );
. . .

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.

Destroy any objects you have created when you no longer need them. While the interpreter theoretically takes care of object cleanup, complex code involving many layers of object instantiation may in some cases cause the interpreter to not release objects in a timely manner. This issue becomes more critical when accessing the application using the Siebel Object Manager. Therefore, explicit destruction of Siebel objects should occur in the procedure in which they are created.

To destroy an object in Siebel eScript, set it to null, or set the variable containing it to another value. The best practice is to destroy objects 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 
 Published: 18 June 2003