Siebel Object Interfaces Reference > Using Siebel Visual Basic and Siebel eScript > Configuring Error Handling >

Guidelines for Using Siebel VB and Siebel eScript


This topic describes guidelines for using Siebel VB and Siebel eScript. It includes the following topics:

For introductory information about Siebel VB, see Siebel VB Language Reference.

Declare Your Variables

To help other developers understand your code and to help you debug your code, it is recommended that you declare your variables.

Declaring Your Variables in Siebel VB

You can use the Dim statement in the Option Explicit statement to declare a variable before you use it. To reduce the amount of memory that your code uses and to improve processing speed, it is recommended that you avoid using a Variant variable. You can declare a variable without specifying a data type. If you do not specify a data type, then Siebel VB assumes the Variant type. This type requires 16 bytes and uses twice as much memory as the next smallest data type.

Use a Standardized Naming Convention

To improve efficiency and reduce errors, it is recommended that all developers in your programming group use the same standardized naming convention. The convention that you use does not matter. Table 8 describes a common convention that prefixes each variable with a letter that indicates the type. If necessary, you can also use a suffix.

Table 8. Naming Conventions for Variables in Scripts
Data Type
Naming Convention
Example

String

s

sName

Integer

i

iReturn

Long integer

l

lBigCount

Single-precision number

si

siAllowance

Double-precision number

d

dBudget

Object

o

oBusComp

Currency

c

cAmtOwed

Use Constants to Standardize Code

Siebel Visual Basic and Siebel eScript provide constants that you can use to make your code more readable by other developers. A constant clarifies the intent of the operation. Use the constant name in your code. Do not use the integer value in your code. The integer value is included only to aid in debugging. If you store the constant in a local variable, and if the value of the local variable is available, then Siebel CRM displays the integer value in the Debugger.

Table 9 lists the Siebel constants you can use.

It is recommended that you use the constant and that you do not use the integer value because integer values are subject to modification.

Table 9. Siebel Constants
Used With
Constant Name
Integer Value

Pre Event Handler Methods

ContinueOperation

1

CancelOperation

2

Search Methods

ForwardBackward

256

ForwardOnly

257

NewRecord Method

NewBefore

0

NewAfter

1

NewBeforeCopy
(Not available with Siebel Java Data Bean)

2

NewAfterCopy
(Not available with Siebel Java Data Bean)

3

Siebel ViewMode Methods. For more information, see Constants You Can Use with the SetViewMode Method.

SalesRepView

0

ManagerView

1

PersonalView

2

AllView

3

OrganizationView

5

GroupView

7

CatalogView

8

SubOrganizationView

9

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;
   }
}

Applying Multiple Object Interface Methods to a Single Object

To apply multiple object interface methods to a single object, you can use the With statement in Siebel VB or Siebel eScript. It reduces typing and makes the code easier to read.

Example of Using the With Statement in Siebel VB

The following example uses the With statement in Siebel VB:

Set oBusObject = TheApplication.GetBusObject("Opportunity")
Set oBusComp = oBusObject.GetBusComp("Opportunity")
With oBusComp
   .ActivateField "Account"
   .ClearToQuery
   .SetSearchSpec "Name", varname
   .ExecuteQuery ForwardBackward
   If (.FirstRecord = 1) Then
      sAccount = .GetFieldValue "Account"
   End If
End With
. . .

Set oBusComp = Nothing
Set oBusObject = Nothing

The following example is not recommended. It does not use the With statement:

Set oBusObject = TheApplication.GetBusObject("Opportunity")
Set oBusComp = oBusObject.GetBusComp("Opportunity")
oBusComp.ActivateField "Account"
oBusComp.ClearToQuery
oBusComp.SetSearchSpec "Name", varname
oBusComp.ExecuteQuery ForwardBackward
If (oBusComp.FirstRecord = 1) Then
   sAccount = oBusComp.GetFieldValue "Account"
End If
. . .

Example of Using the With Statement in Siebel eScript

The following example uses the With statement in Siebel eScript:

var oBusObject = TheApplication().GetBusObject("Opportunity");
var oBusComp = oBusObject.GetBusComp("Opportunity");
with (oBusComp)
{
   ActivateField("Account");
   ClearToQuery();
   SetSearchSpec("Name", varname);
   ExecuteQuery(ForwardBackward);
   if (FirstRecord())
   {
      var sAccount = GetFieldValue( "Account");
   }
} //end with

The following example is not recommended. It does not use the With statement:

var oBusObject = TheApplication().GetBusObject("Opportunity");
var oBusComp = oBusObject.GetBusComp("Opportunity");
oBusComp.ActivateField("Account");
oBusComp.ClearToQuery();
oBusComp.SetSearchSpec("Name", varname);
oBusComp.ExecuteQuery(ForwardBackward);
if oBusComp.FirstRecord();
{
   var sAccount = oBusComp.GetFieldValue("Account");
}
. . .

Use a Self-Reference to Indicate the Current Object

To indicate the current object, you can use the following statements:

  • In Siebel VB, use the Me statement.
  • In Siebel eScript, use the This keyword.

You can use the statement or keyword instead of referencing an active business object.

Example of Using the Me Statement

The following business component event handler uses the Me statement instead of the ActiveBusComp statement:

Function BusComp_PreSetFieldValue(FieldName As String, FieldValue As String) As Integer

If Val(Me.GetFieldValue("Rep %")) >75 Then
   TheApplication.RaiseErrorText("You cannot set the Rep% to greater than 75")
End If
BusComp_PreSetFieldValue = ContinueOperation

End Function

For examples of using the Me statement, see the following topics:

Example of Using the This Keyword

The following business component event handler uses the This keyword instead of the ActiveBusComp statement:

if (condition)
{ ...
   this.SetSearchSpec(...);
   this.ExecuteQuery();
   return (CancelOperation);
}
else
    return(ContinueOperation);

Delete Objects You Have Created That You No Longer Require

Although the interpreter performs object cleanup, it is recommend that you write code that explicitly deletes objects it created that you no longer require. Your code must delete each Siebel object in the same procedure it used to create it.

To delete objects, do the following:

  • In Siebel VB, set each object to Nothing.
  • In Siebel eScript, set each object to Null.

You can delete these objects in the reverse order that the code created them. Make sure you code deletes child objects before it deletes parent objects.

Example of Deleting Objects in Siebel VB

The following code is an example of deleting objects in Siebel VB:

Set oBusObj = TheApplication.GetBusObject("Contact")
Set oBusComp= oBusObj.GetBusComp("Contact")

Your code here

Set oBusComp = Nothing
Set oBusObj = Nothing

Example of Deleting Objects in Siebel eScript

The following code is an example of deleting objects in Siebel eScript:

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

Your code here

oBusComp = null;
oBusObject = null;

Make Sure Function Names Are Unique

Make sure that the name is unique for every function you create. If two functions use the same name, and if those functions are in the same view, then results are unpredictable. Consider using a naming convention, such as using the view name as a function name prefix.

Manage the Script Buffer

The size limit of a non-Unicode script buffer is 65530 bytes. The amount of available memory limits the Unicode script buffer. Make sure your computer possesses enough memory to accommodate this buffer.

Using Siebel VB and Siebel eScript Formats

There are some important differences between the formats that Siebel VB and Siebel eScript use:

  • Siebel eScript is case-sensitive. For example, theApplication is different from TheApplication. Siebel VB is not case-sensitive.
  • Siebel eScript does not distinguish between a subroutine and a function. A subroutine cannot accept an argument. A function can accept an argument. In Siebel eScript, because every object interface method is a function, you must follow it with a pair of parentheses. You must use this technique if the function does or does not accept an argument.

In many instances, the only difference between the Siebel VB format and the Siebel eScript format is that the Siebel eScript format requires a pair of parentheses at the end. In these instances, this book only includes the Siebel VB format. To determine the Siebel eScript format, add the parentheses.

Differences Between Siebel eScript and ECMAscript

ECMAscript is a programming language that developers use to script a client on the Web. JavaScript is a type of ECMAscript. Siebel eScript does not include user interface functions. You cannot use it to animate or control a Web page. It includes the following functions that are not part of ECMAscript:

  • SELib
  • Clib

You can use these functions to interact with the operating and file systems, and for performing input and output file operations. These objects include functions that are similar to functions that the C programming language uses. For more information, see Siebel eScript Language Reference.

ECMAscript does not require you to declare a variable. It declares a variable implicitly as soon as you use it.

Handling the Date Format in Siebel VB

If you use an object interface method that includes a date, then use caution regarding the date format. The GetFieldValue method returns the date in the following format:

dd/mm/yyyy

The CVDate function expects the regional setting. If you apply it, then Siebel CRM might return an error. The GetFormattedFieldValue method uses the regional settings of the operating system that is installed on the computer that runs the Siebel client. The regional setting might specify the year with two digits, and can cause an error with the year 2000 problem. For these reasons, use the following procedure for performing date arithmetic.

To handle the date format in Siebel VB

  1. To return the value of the date fields, use the GetFieldValue object interface method.

    For more information, see GetFieldValue Method for a Business Component.

  2. Use the DateSerial function convert the value of the date field to a date variable.
  3. Perform the required date arithmetic.

    For example, you can use the following Siebel VB code:

    Dim strDate as String, varDate as Variant
    strDate = oBC.GetFieldValue("Date Field")
    varDate =DateSerial(Val(Mid(strDate,7,4)),Val(Left(strDate,2)),_
       Val(Mid(strDate,4,2)))
    any date arithmetic

Returning Run-Time Errors in Siebel VB

This topic describes how to return run-time errors in Siebel VB.

To return run-time errors in Siebel VB

  • Return a run-time error code with one of the following items:
    • Predefined Siebel VB properties. You can use some combination of Err, ErrText, and Error.
    • Custom Siebel VB method. If you access a Siebel object interface through Component Object Model (COM) or ActiveX, then use the following code to view the text of the error message:

    If errCode <> 0 Then
       ErrText = GetLastErrText
       TheApplication.RaiseErrorText ErrText
       Exit Sub
    End If

The GetLastErrText method is only available if you use an interface that is external to Siebel Tools. You can use it in Microsoft VB but not in Siebel VB.

Object interface methods use numeric error codes in a range of 4000 to 4999.

For more information about error-handling and error codes, see Siebel VB Language Reference.

Siebel Object Interfaces Reference Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices.