P. 1
46994071 Siebel Scripting Best Practices

46994071 Siebel Scripting Best Practices

|Views: 466|Likes:

More info:

Published by: Raghu Babu Yarramasu on Mar 06, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/17/2012

pdf

text

original

Sections

  • Scripting: Where to Begin
  • Basic Process Flow
  • Scripting Best Practices
  • When to Use Scripting
  • Follow Standard Naming Conventions
  • Comment Code
  • Know When to Use Browser versus Server Script
  • Place Code in the Correct Event Handler
  • Use Fast Script In Event Handlers that Fire Frequently
  • Runtime versus Compiled Business Services
  • Use Option Explicit
  • Leverage Appropriate Debugging Techniques
  • Remove Unused Code from the Repository
  • Include Error Handling in All Scripts
  • Use RaiseError and RaiseErrorText Properly
  • Use Exception Information
  • Place Return Statements Correctly: eScript
  • Centralize Browser Script Using the “Top” Object
  • Know When to Use the Current Context versus a New Context in Server Script
  • Use Smallest Possible Scope for Variables
  • Instantiate Objects Only As Needed
  • Destroy Object Variables When No Longer Needed
  • Use Conditional Blocks To Run Code
  • Verify Objects Returned
  • Verify Field is Active before Use
  • Leverage New Methods in Siebel 7
  • Use Proper View Mode For Queries
  • Query Only Indexed Columns
  • Use ForwardOnly Cursor Mode
  • Verify Existence of Valid Record After Querying
  • Use Switch or Select Case Statements
  • Compare the Same Condition In If/Else If
  • Use the Associate Method to Create Intersection Table Records
  • Use Dynamic Values
  • Use Logical Constants versus Literal Values
  • Avoid Exit Function and Exit Sub
  • Place GotoView at the End of a Script
  • Use DeleteRecord Method Properly

Siebel Scripting Best Practices Resource Document

This resource document contains detailed information regarding scripting best practices.

Siebel Systems, Inc.

SIEBEL SYSTEMS, INC. EMPLOYEE EDUCATION

1

PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED

SIEBEL SCRIPTING BEST PRACTICES

MARCH 23, 2004

Copyright © 2004 Siebel Systems, Inc., 2207 Bridgepoint Parkway, San Mateo, CA 94404. All rights reserved. No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photographic, magnetic, or other record, without the prior agreement and written permission of Siebel Systems, Inc. Siebel Systems, Inc. considers information included in this document to be Confidential and Proprietary. Your access to and use of this Confidential and Proprietary Information is subject to the terms and conditions of the Siebel License Agreement or Non-Disclosure Agreement which has been executed and with which you agree to comply.

PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED

2

SIEBEL SYSTEMS, INC. EMPLOYEE EDUCATION

MARCH 23, 2004

SIEBEL SCRIPTING BEST PRACTICES

Table of Contents
In Acrobat, you can click on any lesson or topic to jump to that area of the resource document. You can also use the Bookmarks feature in Acrobat to quickly navigate.

SCRIPTING FUNDAMENTALS
Scripting: Where to Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Basic Process Flow

Basic Process Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1. 2. 3. 4. 5. 6. Explore Declarative Configuration Alternatives Determine Where to Put the Script: Which Object? Determine Where to Put the Script: Which Event? Add Error Handling Template Add Method Body Test

SCRIPTING BEST PRACTICES
When to Use Scripting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Use Scripting as a Last Resort

Follow Standard Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comment Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Know When to Use Browser versus Server Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Place Code in the Correct Event Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use Fast Script In Event Handlers that Fire Frequently. . . . . . . . . . . . . . . . . . . . . . . . . . . Runtime versus Compiled Business Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use Option Explicit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Leverage Appropriate Debugging Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Siebel Applications Alert and RaiseErrorText Writing to a Text File Using the Debugger in Siebel Tools Using Object Manager Settings

10 11 13 14 15 16 17 18

Remove Unused Code from the Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Include Error Handling in All Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Proper Error Handling Error Handling in eScript Error Handling in Siebel VB

Use RaiseError and RaiseErrorText Properly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Use Exception Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Purpose of Exception Handling Exception Information in eScript Exception Information in Siebel VB

Place Return Statements Correctly: eScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Centralize Browser Script Using the “Top” Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

SIEBEL SYSTEMS, INC. EMPLOYEE EDUCATION

3

PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED

SIEBEL SCRIPTING BEST PRACTICES

MARCH 23, 2004

Know When to Use the Current Context versus a New Context in Server Script. . . . . . . 31
Difference Between Current and New Context Guidelines for Choosing Context

Use Smallest Possible Scope for Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Instantiate Objects Only As Needed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Destroy Object Variables When No Longer Needed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Use Conditional Blocks To Run Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Verify Objects Returned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Verify Object Returned is Expected One ActiveBusObject ActiveBusComp ParentBusComp

Verify Field is Active before Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Leverage New Methods in Siebel 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
New Methods

Use Proper View Mode For Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Query Only Indexed Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Use ForwardOnly Cursor Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Verify Existence of Valid Record After Querying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Use Switch or Select Case Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Compare the Same Condition In If/Else If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Use the Associate Method to Create Intersection Table Records . . . . . . . . . . . . . . . . . . . . 49 Use Dynamic Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Use Logical Constants versus Literal Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Avoid Exit Function and Exit Sub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Place GotoView at the End of a Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Use DeleteRecord Method Properly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED

4

SIEBEL SYSTEMS, INC. EMPLOYEE EDUCATION

MARCH 23, 2004

SIEBEL SCRIPTING BEST PRACTICES

Scripting Fundamentals
Scripting: Where to Begin
Basic Process Flow This flowchart outlines the basic process for developers to follow when writing script.

The objective is to minimize script—writing it only when necessary, and writing it once!

SIEBEL SYSTEMS, INC. EMPLOYEE EDUCATION

5

PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED

Writing script at the business component level prevents developers from having to re-write it on applets that leverage the same underlying business component. Siebel Systems encourages developers to use business services. If the same script is seen in many business components with only slight differences. If the method facilitates interaction with the client’s desktop or communication with the user. use the Pre. write the script at the applet server level. This only makes sense if the method is specific to a particular business component. and business services. that business component is the most likely object for the script. as they can be called by workflow processes. This enables developers to write the script once for use by many objects. If the method controls the behavior of an applet. move the script to a business service and parameterize it. Determine Where to Put the Script: Which Event? After determining the appropriate object. Determine Where to Put the Script: Which Object? Before writing any script. 2004 SIEBEL SCRIPTING BEST PRACTICES Basic Process Flow 1. After determining that the solution requires script. 3. If the method deals with data in a specific business component. This is an important step! It ensures that developers write script only when there is no configuration alternative. This is a proactive approach: you are trying to stop or modify something the user is doing before it gets too far. Business component There are two ways to think of scripting a business component: proactively and reactively. PreSetFieldValue. A utility script that will be called from many locations such as applets. but do not need to change data in any record other than the current record. Continued on next page SIEBEL SYSTEMS. is best implemented as a business service. for example. An alternative to writing a business service is to write the method at the application level.MARCH 23. EMPLOYEE EDUCATION 6 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . developers must determine the appropriate event within that object.event (for example. INC. if it is enabling a button or hiding/showing list columns or controls. make the script an applet browser script. developers should explore all declarative configuration alternatives. PreWriteRecord). If you need to perform some sort of validation. thus minimizing the amount of script. PreQuery. business components. workflow processes cannot call custom application level methods. Explore Declarative Configuration Alternatives 2. developers must determine where to put the script.

however. Continued 3. Continued on next page SIEBEL SYSTEMS. If these processes fail.events to change data in a record other than the current record. If. When taking a reactive approach. If the method deals with data specific to the business component. Ideally. can call a business service. Methods that interact with the user’s desktop. Determine Where to Put the Script: Which Event? Continued Never use Pre. the user. This is quite often a workflow process or some sort of integration. write the script on the applet. or how the applet looks. the method deals with something specific to the applet.event occurs before the Siebel application runs its own field-level validations and other processes in the underlying C++ class that might fail. should originate in this event. To perform further processing after a change has been applied. even browser script. for example. write a server script in the WebApplet_PreInvokeMethod event. A reactive script typically applies to the WriteRecord event. write a method that can accept parameters to operate for a wide range of needs. Business Service This is the best place to write script that will be called from anywhere. significantly simplifying maintenance efforts. The Pre. it is an ideal location for many situations. Siebel Systems recommends not putting all of the method script in the Service_PreInvokeMethod. then the business component is the appropriate place for the method. create custom methods and call those methods from this event. EMPLOYEE EDUCATION 7 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Rather. If the method accesses data in a record other than the current record or active business component. the Siebel application exits the Pre.event and does not roll back any changes to other objects. This eliminates the need to duplicate code across objects and events.MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Basic Process Flow. after the application writes a record. Rather. it is acceptable to manipulate data in records other than the current record. implement a reactive script. Siebel Systems recommends not putting all of the method code in the Applet_PreInvokeMethod event. Remember that you are trying to reduce the amount of script written. Applet Most scripting for applet browser functionality will originate in the Applet_PreInvokeMethod event. INC. This could leave the application in an inconsistent state. Duplicating script is a common problem which frequently leads to thousands of pages of script! Since any script. This is where developers can trap methods invoked on an applet. break it into smaller scripts that the Service_PreInvokeMethod event of a business service can call.

so that you can catch any runtime errors. Failure to test completely results in more wasted time later trying to track down a bug. When to use TheApplication event instead of a Business Service will depend on your requirements. EMPLOYEE EDUCATION 8 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . implement the functionality as a business service. as stated earlier). 5. Therefore. Now you are ready to write the actual method. “Sandwich” this code within the error handling code. 4. 2004 SIEBEL SCRIPTING BEST PRACTICES Basic Process Flow. Applying the error handling skeleton to a method before writing the method. they have limited visibility: application-level browser script may only be called by other browser scripts. While application-level scripts do centralize methods. Workflow processes cannot access methods defined at the application level. Add Error Handling Template Put an error/exception handling strategy in place before writing any script. or to workflow processes. Add Method Body 6. INC. if requirements dictate that methods be visible to both server and browser script.MARCH 23. Determine Where to Put the Script: Which Event? Continued The Application This is a good place for methods that need to fulfill the needs of many disparate calling scripts (as is a Business Service. Make sure the tests are complete. assures two things: • error handling is present and • future manipulation of the method will not cause a runtime error that goes unnoticed. Continued 3. covering all possible conditions. and application-level server script only works for server scripts. This is the last and most important step of scripting. Test SIEBEL SYSTEMS. This includes creating an error handling template that you can apply to all scripted events.

Before writing any script. leading to a lower total cost of ownership. Siebel Systems highly recommends that you review the media-based training (MBT) titled Declarative Alternatives to Siebel Scripting. For more information about this MBT. log on to Siebel University at http://siebeluniversity. INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Scripting Best Practices When to Use Scripting Use Scripting as a Last Resort Do not write script if there is a way to implement the required functionality through configuration. Preferred alternatives to scripting include • Field validation • User properties • Workflow • Personalization • Run-time events • State model SIEBEL SYSTEMS.MARCH 23. Declarative configuration is easier to maintain and upgrade.com.siebel. EMPLOYEE EDUCATION 9 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .

MARCH 23. EMPLOYEE EDUCATION 10 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Data types Data Type Integer String Boolean Float Scope Scope Global Scope (only applicable for Siebel VB) Module/Instance Scope Function or Local Scope Modifier G_ M_ or i_ No modifier or l_ Prefix I S B f SIEBEL SYSTEMS. INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Follow Standard Naming Conventions Have the project team agree upon a standard way of naming variables so that the scope and data type are identified easily. This significantly simplifies maintenance and troubleshooting efforts.

comment lines that perform non-standard or complex behavior. Include a comment header at the top of a method with an explanation of the code and revision history. At the onset of a project. If you do not maintain them along with the code. ' [BusComp_ChangeRecord] ' Evaluated and Set to 1 here ' ' NOTE: ' History Continued on next page Procedure might be called recursively!!! oBC1BusComp BusComp for ABC (positioned) oBC2BusComp BusComp for XYZ (not yet positioned) MyProcedure() BusComp [Account] ' SIEBEL SYSTEMS. Example of comment header: ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Name: ' Module: ' Arguments: ' ' ' ' ' Return Value: Integer ContinueOperation -> Relationship is ' OK ' CancelOperation -> Relationship is ' not OK ' ' Used Globals: gintCheckIt Set to 1 in ' [Quote]. and simplify the maintenance effort. or incorrect. INC. misleading. EMPLOYEE EDUCATION 11 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .[BusComp_ChangeRecord] ' Evaluated and Reset here ' ' Static Vars: mintChecked Set to 0 in [Account]. project teams should agree upon standard commenting practice to ensure consistency.MARCH 23. Strictly maintain these headers so that they accurately reflect the script that they describe. eventually they become confusing. As well as adding a comment header. 2004 SIEBEL SCRIPTING BEST PRACTICES Comment Code Commenting code is a very good practice to explain the business purpose behind the code.

MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Comment Code. EMPLOYEE EDUCATION 12 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Continued ' Date AuthorPurpose ' 8/14/03SBoetigOriginal Creation ' ' Description: This procedure contacts Webline and retrieves ' a bunch of data that is stored on the ' Action BC in Siebel to maintain a sort of ' audit record. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' SIEBEL SYSTEMS. INC.

MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Know When to Use Browser versus Server Script Browser script is recommended for: • Communication with the user • Interaction with desktop applications • Data validation and manipulation limited to the current record Server script is recommended for: • Query. EMPLOYEE EDUCATION 13 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . INC. and delete operations • Access to data beyond the current record SIEBEL SYSTEMS. insert. update.

and WriteRecord. SetFieldValue. Determine Where to Put the Script: Which Event?” on page 6 for more information). therefore it is safe to create or modify data in other objects. When this event fires. The companion events. you know that the record exists. without fearing orphaned records or an inconsistent state of the application. and therefore are the appropriate events for such manipulation. the WriteRecord event fires after the record writes successfully. Do not use Siebel application Pre. PreSetFieldValue. and PreWriteRecord) to manipulate data in objects other than the one hosting the script. such as Query. INC. eScript examples BusComp_PreSetFieldValue BusComp_PreWriteRecord BusComp_SetFieldValue BusComp_WriteRecord Field level validation Record level validation Field triggered actions Record triggered actions Example: synchronizing two business components or creating activities BusComp_PreQuery Code control over SearchSpecs SIEBEL SYSTEMS. (See “3. For example. occur after the internal and field-level validations succeed. 2004 SIEBEL SCRIPTING BEST PRACTICES Place Code in the Correct Event Handler One of the most common issues identified during script reviews is the inappropriate use of object events.events (such as PreQuery. Placing code in the wrong event handler can lead to corrupt data and may negatively impact performance.MARCH 23. EMPLOYEE EDUCATION 14 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .

2004 SIEBEL SCRIPTING BEST PRACTICES Use Fast Script In Event Handlers that Fire Frequently Avoid placing complex code in event handlers that fire frequently. as it may degrade application performance. The calculated field holds the display value and the calculation performs the logic. As an alternative. SIEBEL SYSTEMS. The PreGetFieldValue event fires at least once for every field that is retrieved. In this case.MARCH 23. More detail on this function and its suggested use can be found in the Siebel Bookshelf. developers can use a calculated field. make the script as simple as possible. Developers typically use script in the PreGetFieldValue event to return a value other than the one in the database. One alternative for complex calculations is to create a calculated field that uses the InvokeServiceMethod function. such as BusComp_PreGetFieldValue. EMPLOYEE EDUCATION 15 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . and if none is available. not the actual field. Complex script in this event handler significantly degrades application performance. For other frequently fired events. to the user. look for a configuration alternative. the Siebel application exposes the calculated field. INC. This can amount to hundreds of calls to the event in rapid succession.

they provide more security than runtime services and they are faster to load. You must compile and implement a new .srf file. Since no compiling is required. SIEBEL SYSTEMS. the developer can choose whether the business service should remain as a runtime service or if it should be migrated to Siebel Tools. The database stores them as records and you can change them at any time. Compiled business services are defined in Siebel Tools and represent a functionality that needs more security and is not likely to change. This can pose a security problem. Runtime business services are not compiled into the . The decision on whether to make a business service compiled or runtime has no hard and fast rules.srf file to implement any changes.MARCH 23. code development may be faster in the runtime environment.srf file. INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Runtime versus Compiled Business Services Business services may be defined in Siebel Tools and compiled with the . This makes them useful for logic that changes frequently and logic that you need to change without deploying a new . It ultimately depends on what you intend the service to do and how frequently you expect the code in the business service to change. For clarity. Because these business services are compiled. The next time a runtime service executes. Runtime business services can be useful in a development environment to test frequent changes to scripts by using the business service simulator. The drawback to a runtime business service is that anyone with access to the view can see the code. you should inactivate or delete the runtime version so that it is clear to all developers that the runtime version is no longer being used. or created as runtime business services in the client user interface. EMPLOYEE EDUCATION 16 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .srf file. if you migrate a business service from a runtime version to a compiled version. the compiled version executes and the runtime version is ignored. Once the code is complete and tested through the simulator. it uses the changes to the definition. Note: If you define a business service called MyService as a runtime business service and as a compiled business service.

Option Explicit catches that a variable is being used that has not been defined. Example: if you defined a variable called ls_description. 2004 SIEBEL SCRIPTING BEST PRACTICES Use Option Explicit Include the Option Explicit in the <general> <declarations> section of every object containing Siebel VB code. Option Explicit requires that you explicitly declare every variable. SIEBEL SYSTEMS. Since Option Explicit only evaluates during compile time. there is no performance impact. Without Option Explicit. the application defines a new variable as ls_dscription. EMPLOYEE EDUCATION 17 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . thus simplifying debugging efforts. and later reference the variable as ls_dscription (missing an ‘e’). Without Option Explicit.MARCH 23. INC. the Siebel application defines and dimensions variables on the fly. The compiler returns an error if the Siebel application uses a variable before declaration.

2004 SIEBEL SCRIPTING BEST PRACTICES Leverage Appropriate Debugging Techniques Debugging Siebel Applications It is essential that you understand how to debug Siebel applications.MARCH 23. Defined in the Component Parameters View: • OM . Writing to a Text File The most common way to debug a script is to write information to a text file. developers or systems administrators can change settings in the object manager to trace events and SQL. The RaiseErrorText method stops the execution of a script. In this situation. Alerts do not stop the execution of browser scripts and therefore are a quick and easy way to debug browser scripts. EMPLOYEE EDUCATION 18 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . You can set break points anywhere until you isolate a problem.Trace EL Events: traces which events are triggered (Set to 1) • OM . it is not always possible to add debugging statements to script. therefore. SADMIN) • OM . Using Trace. you can write the actual SQL to a file.EL Tracing User Name: a comma separated list of logins to trace (for example.Trace EL Allocation: traces object memory allocation (Set to 1) • OM . There are four basic techniques: • Use alerts or RaiseErrorText methods to pop up message boxes • Write to a file using Trace or custom methods • Use the Siebel Debugger • Use object manager level logging The alert method in browser script and the RaiseErrorText method in server script enable you to display message boxes to the user.Trace EL SQL: traces the SQL generated by script (Set to 1) Continued on next page Alert and RaiseErrorText Using the Debugger in Siebel Tools Using Object Manager Settings SIEBEL SYSTEMS. Accomplish this using the Trace function or an Siebel VB or eScript function. it is only appropriate for a quick check of something and is not a good way to debug scripts where the source of the error is hard to determine. INC. This is a useful tool for visually stepping through the code and looking at the values of variables real time. When an application is in production.

MARCH 23. Continued Using Object Manager Settings Continued Defined in the Component Event Configuration View: • Object Manager Extension Language Log: enables the scripting to be logged (Set to 1) This graphic shows the two locations in the Siebel client application where object manager logging is turned on. SIEBEL SYSTEMS. 2004 SIEBEL SCRIPTING BEST PRACTICES Leverage Appropriate Debugging Techniques. For the log level changes to take effect immediately. INC. EMPLOYEE EDUCATION 19 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . modify the Current Value parameter.

of file type . you can do an export from Siebel Tools to save a copy of the script. SIEBEL SYSTEMS. This can be confusing to developers who think the event is scripted due to its Active status.js if the script is written in eScript. EMPLOYEE EDUCATION 20 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Archive files contain all property definitions for the object.MARCH 23. Remove Empty Methods Example of empty method in Siebel VB Sub Application_Start (CommandLine As String) End Sub The event handler for an empty method shows up as Active in Siebel Tools. INC.sbl if it is written in Siebel VB. 2004 SIEBEL SCRIPTING BEST PRACTICES Remove Unused Code from the Repository Remove code that is: • Commented out • Set to Inactive • Never called If you want to keep a record of obsolete code before removing it. empty methods can cause a small performance hit as the interpreter may run through the event handler unnecessarily. The script for all methods on that object will be exported to a file of type . To export a script to a text file. open the script editing window for the object in question.sbl file only contains the script. Alternatively.js or . you can create an archive file. with the object containing the script. then choose File > Export. whereas a . Also.sif. or .

}//end try The try keyword precedes a block of normal processing code that may throw an exception.. Proper error handling: • Returns custom error messages that are easier for the user or developer to interpret • Is “bulletproof”.. */ . • Catch block: captures the error. external COM objects or the OS Error Handling in eScript Implement eScript error handling through the try/catch/finally mechanism.executable code goes here. Continued on next page SIEBEL SYSTEMS. Example: function illustrateErrorHandling() { try { /*The try block encompasses all statements that could cause an exception.. • Finally block: performs any cleanup work such as destroying object references. Without proper error handling. • Try block: contains the logic that you want performed.MARCH 23. covering all methods that access Siebel Objects.. INC. EMPLOYEE EDUCATION 21 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . users may receive run-time errors from the interpreter. 2004 SIEBEL SCRIPTING BEST PRACTICES Include Error Handling in All Scripts Proper Error Handling Proactive handling of errors or exceptions significantly streamlines debugging. which are difficult to understand.

MARCH 23. “ + “ERROR: ” + e.callee substitutes the method name in which the code is running. After a try block throws an exception. 2004 SIEBEL SCRIPTING BEST PRACTICES Include Error Handling in All Scripts.Name() + “ object. Continued Error Handling in eScript Continued catch(e) { if(defined(e.Name() substitutes the object name in which the script is running. • this.RaiseErrorText(“An exception occurred ” + “in the “ + “ of the “ + } }//end catch arguments. Use two methods to avoid hard coding the object and method names. control over the program flow switches to the first catch block following it. “ + “ERROR: ” + e.Name() + “ object.callee + this. INC.toString()).errText)) { TheApplication(). • arguments. EMPLOYEE EDUCATION 22 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Continued on next page SIEBEL SYSTEMS. Using these methods allows developers to copy this catch block into any eScript server script routine without changing it at all.RaiseErrorText(“An exception occurred ” + “in the “ + arguments. The catch keyword precedes a block of exception handling code. } else { TheApplication().errText + “STACK: ” + e.callee + “ of the “ + this.toString()).

INC. for example: bcContact = null. it will continue processing as if nothing happened. Continued on next page SIEBEL SYSTEMS. Error Handling in Siebel VB There are two strategies for handling unexpected runtime errors in Visual Basic: 1. On Error Resume Next: traps the runtime error in the Err object and continues right along as though nothing happened. EMPLOYEE EDUCATION 23 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . 2004 SIEBEL SCRIPTING BEST PRACTICES Include Error Handling in All Scripts. If no error handling is done immediately after Err object detects an error. On Error Goto <label>: traps runtime errors in the Err object and transfers control immediately to the label specified. Siebel Systems recommends using On Error Goto <label> unless there is a compelling reason to use Resume Next. } The finally block always executes. 2. Continued Error Handling in eScript Continued finally { // // // This block will always be called whether an exception is thrown or not. boAccount = null.MARCH 23. This is a dangerous form of error handling because it essentially ignores all errors. It can perform code cleanup and write the error parameters to a log file. so it is an ideal location for the final release of resources. after which the procedure may gracefully exit and inform the user of the error condition. put the cleanup code here.

SIEBEL SYSTEMS. Whether created by developers in the script above. Use the if condition to make sure that the Siebel application enters this error handling block only if an error occurred. raised by a function called in the script above.MARCH 23. the Err variable will not contain zero. " & Chr$(13) & _ "Error number: " & Err & Chr$(13) & _ "Error text: "Error line: End If " & Error$ & Chr$(13) & _ " & Erl Notice the use of Err object and Error function in the Application. Continued Error Handling in Siebel VB Continued Example of On Error Goto <Label> Sub illustrateExceptionHandling() ‘In the event of an error.RaiseErrorText “An error has occurred ”& _ “illustrateExceptionHandling method ” & Chr$(13) & _ "object. processing will immediately ‘transfer to the label “errorhandler” On Error GoTo errorhandler ‘Place code here that may experience an error Dim lBO_test Dim lBC_test As BusObject As BusComp Set lBO_test = TheApplication. EMPLOYEE EDUCATION 24 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Include Error Handling in All Scripts.GetBusObject(“Account”) Set lBC_test = lBO_test.GetBusComp(“Account”) errorhandler: Set lBC_test = Nothing Set lBO_test = Nothing If Err <> 0 Then TheApplication.RaiseErrorText function to retrieve error code and error text. or created by the Siebel application because of some runtime condition.

however.MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Use RaiseError and RaiseErrorText Properly In Siebel 7. it is important to place any code that must execute before calls to these methods. developers sometimes use RaiseError and RaiseErrorText to display message boxes via script. SIEBEL SYSTEMS. Therefore. which was available in version 6. EMPLOYEE EDUCATION 25 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . RaiseError and RaiseErrorText methods generate a server script exception causing the script to stop executing at that point. INC.x and earlier. these methods do not serve the same purpose as the MsgBox method.

INC.MARCH 23. “ + “ERROR: ” + e. • Stack trace: the list of methods in the order in which they executed up to the line where the exception occurred.callee + “ of the “ + this. “ + “ERROR: ” + e. } else { TheApplication().errText • Populates when the Siebel application encounters an error during runtime or when the developer raises an exception using RaiseErrorText. It • • • • • is the duty of the exception handling to Catch exceptions Stabilize the application Log exception information or notify the users of what happened Possibly. set a return code Exception Information in eScript In eScript. This is an array of parameters specific to the method being invoked.errText + + e. the exception object stores error information in the: • errText attribute: exception.Name() + “ object.toString()). 2004 SIEBEL SCRIPTING BEST PRACTICES Use Exception Information Purpose of Exception Handling Do not ignore exceptions.toString()).errText)) { TheApplication(). In eScript.RaiseErrorText(“An exception occurred ” + in the “ } Continued on next page + arguments. EMPLOYEE EDUCATION 26 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . re-throw the exception Possibly. “STACK: ” SIEBEL SYSTEMS. you can obtain the method name dynamically from a native property of the method called “arguments”.toString() • Provides exception information from a COM object or from an exception thrown by the developer using the throw statement.callee + “ of the “ + this. Example: if(defined(e. There are two types of information: • Error description: the description of what went wrong. Ignoring them can cause other runtime errors to occur. • toString() method: exception.Name() + “ object.RaiseErrorText(“An exception occurred ” + “in the “ + arguments.

2004 SIEBEL SCRIPTING BEST PRACTICES Use Exception Information. the Err object stores the error information. " & Chr$(13) & _ "Error number: " & Err & Chr$(13) & _ "Error text: "Error line: End If " & Error$ & Chr$(13) & _ " & Erl SIEBEL SYSTEMS.RaiseErrorText "An error has occurred " & _ “illustrateExceptionHandling method ” & Chr$(13) & _ "in the " & Me.Name & _ " object. Continued Exception Information in Siebel VB In Siebel VB. INC. Because Siebel VB does not include properties that store the method name. EMPLOYEE EDUCATION 27 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . you must hard code the method name in the string passed to the RaiseErrorText method.MARCH 23. Example: If Err <> 0 Then TheApplication.

RaiseErrorText("An exception occurred " + "in the " + " of the " + } }//end catch finally { //cleanup code goes here } return myVar. When code in the finally clause causes an exception.errText + "STACK: " + e. null. or an exception. but the original exception information is lost. 2004 SIEBEL SCRIPTING BEST PRACTICES Place Return Statements Correctly: eScript A return statement in the finally clause of a try/catch/finally block suppresses any exceptions generated in the method or thrown to the method. These exceptions will not make it out of the method.errText)) { TheApplication(). Example: function illustrateReturnStatement() { var myVar. INC.callee + this. A method takes input. } arguments.toString()). and then returns a value.callee + " of the " + this. } else { TheApplication(). does something.RaiseErrorText("An exception occurred " + "in the " + arguments.MARCH 23.toString()). Ensure that the method itself contains the return statement.Name() + " object. " + "ERROR: " + e. } catch(e) { if(defined(e. SIEBEL SYSTEMS. EMPLOYEE EDUCATION 28 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . the exception information makes it out of the method. " + "ERROR: " + e. try { //executable code goes here myVar = 1.Name() + " object.

log = trace_log. This step assigns a function pointer to the top window object of the application.. INC. { After adding the function to the (general) (declarations) section. being a browser script object. This is useful for any function which needs to interact programmatically with a client application or desktop.MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Centralize Browser Script Using the “Top” Object In browser script. Thus the top object. Assign a pointer for the method to the top object: • Include Top in (general) (declarations) of Application object top. top is a shortcut to the top level document. 2. can only be referenced from browser script. Note: Scripted objects have a server side aspect which can only call server script and a browser side aspect which can only call browser script.. Implement the method at the application level function trace_log(as_text) { . Using the top object. which any browser script can use. developers can write a browser script function once and call it from anywhere within the browser aspect of objects. that would also need to be called from multiple places in the application.include trace logic here. The following example provides a logging function in the top object: 1. as shown below: Continued on next page SIEBEL SYSTEMS. you will see it appear as a separate function in the script window. EMPLOYEE EDUCATION 29 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .

Call the method from any browser script. INC.MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Centralize Browser Script Using the “Top” Object. SIEBEL SYSTEMS. Continued 3. EMPLOYEE EDUCATION 30 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .

GetBusComp(“Contact”). This message appears because the script has modified the current record. create a new. The difference here is the business object. Equivalent ways of getting a reference to the current Contact business component instance are bc = TheApplication(). To prevent users from seeing data manipulation that the script does. Continued on next page SIEBEL SYSTEMS. instance of the Contact business component. bc = bo. or non-UI. consider a script running in any event of the Contact business component that needs to get a reference to the Contact business component to do a comparison or lookup.MARCH 23. the user sees any programmatic manipulations of the data. INC.ActiveBusObject().GetBusComp(“Contact”).BusObject(). 2004 SIEBEL SCRIPTING BEST PRACTICES Know When to Use the Current Context versus a New Context in Server Script Difference Between Current and New Context • • Current (or UI) context deals with objects that the Siebel application created to support data that are currently available to the user. bc = this. enabling data manipulation to occur outside of the current context.GetBusComp(“Contact”). it is the business object that makes the difference. Keeping these two straight is important because the user may see programmatic manipulations of data if you use the wrong context. EMPLOYEE EDUCATION 31 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .GetBusComp(“Contact”). the warning message “The selected record has been modified by another user since it was retrieved” will be displayed to the user. In this previous code example. For example. Note that when the current record is instantiated and modified in a non-UI context instance. Since all business components live within an enclosing business object’s context. If this code is executed while a user is watching the user interface. if the script is going to update the current record. This code returns a reference to the current instance of the Contact business component: bc = this. and a refresh is necessary for the user to see the current field values. bo = TheApplication. New (or Non-UI) context is a set of objects instantiated in script that have no tie to any objects or data that the user is currently viewing. it may be preferable to use the UI context to avoid this message. Therefore. the application created a new instance of the Contact business object.

EMPLOYEE EDUCATION 32 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Know When to Use the Current Context versus a New Context in Server Script.MARCH 23. Continued Guidelines for Choosing Context • Use the current context to • Access data with which the user is currently working • Perform processing that should be visible to the user Use a new context to • Invisibly query a visible business component • Use a business component in a different business object context • SIEBEL SYSTEMS.

Scripts often step on each other.MARCH 23. There is no event that guarantees that the objects are always destroyed. SIEBEL SYSTEMS. INC. 1. It is difficult to “understand” the scope or state of variables. 4. This is done at the application level so that any script can access the objects. 2. because they are instantiated in one method and accessed in others. Rules of encapsulation are usually violated. EMPLOYEE EDUCATION 33 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . 3. it is a bad practice for four reasons. 2004 SIEBEL SCRIPTING BEST PRACTICES Use Smallest Possible Scope for Variables Developers frequently create instance level variables that can be accessed by many methods within an object. It is far better to declare and use objects where they are needed and pass them as parameters to other methods. While this is good for the purposes of instantiating an object only once.

Evaluate condition 2. Evaluate condition 3. Create objects 2. 2004 SIEBEL SCRIPTING BEST PRACTICES Instantiate Objects Only As Needed Create object instances on an as-needed basis.MARCH 23. EMPLOYEE EDUCATION 34 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Create objects 3. Otherwise. INC. Create object instances that are needed based upon the outcome of an evaluation after that evaluation. your code may create unused object instances that can negatively impact performance. Use objects Incorrect order 1. Correct order 1. Use objects SIEBEL SYSTEMS.

MARCH 23. 2004 SIEBEL SCRIPTING BEST PRACTICES Destroy Object Variables When No Longer Needed Memory leaks are a common problem. ParentObject = null. that same script must destroy the object reference before leaving the method. Release objects in the reverse order in which the Siebel application created them. finally { ChildObject } = null. destroy objects in the finally clause as this clause always executes. regardless of whether the method exits successfully or with errors. • Pick/Associate/MVG business components before the parent business component • Business components before business objects • No specific order for property sets and business services since they are independently created from the application Tightly couple object destruction with error handling to ensure that the Siebel application destroys objects in success and in failure. INC. parent objects second. destroy an object by setting it to nothing (Set oBC = Nothing). destroy an object by setting it to null (oBC = null). so when a script creates an object reference. child objects first. EMPLOYEE EDUCATION 35 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Object references are: • COM objects • Property Sets • Business Services • Business Components • Business Objects • Applets In eScript. Therefore. In Siebel VB. SIEBEL SYSTEMS.

2004 SIEBEL SCRIPTING BEST PRACTICES Use Conditional Blocks To Run Code Just as objects should be instantiated only as needed. … } … } SIEBEL SYSTEMS. Example: function BusComp_PreSetFieldValue(FieldName. A typical example is in the BusComp_PreSetFieldValue event. code should be run only as needed. EMPLOYEE EDUCATION 36 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . not all fields. Check which field the code is modifying before going any further. Code in this event is usually associated with a specific field. FieldValue) { switch(FieldName) { case “Status”: …do something… break.MARCH 23. INC.

MARCH 23. check which object is actually returned from a call to this method. INC. The link that established a parent/child relationship in the business object has been removed or changed. EMPLOYEE EDUCATION 37 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .ActiveBusObject(). ActiveBusObject returns the business object for the business component of the active applet.BusObject (in an applet and in a business component) this. Script running in an applet or in a business component should use: • • Me. (in an applet and in a business component) eScript Example: if(TheApplication().BusObject(). Two situations could cause no reference to return: • • The business component is the parent and has no parent. especially when calling methods such as ActiveBusObject. verify the active business component with a call to this method. such as the Account business component in the Account business object. ActiveBusComp. 2004 SIEBEL SCRIPTING BEST PRACTICES Verify Objects Returned Verify Object Returned is Expected One ActiveBusObject Always verify that the object returned is the one expected. and ParentBusComp. When running script outside of a business component. ActiveBusObject only makes sense if used in a script running in the application object or in a business service. ParentBusComp returns the parent business component when given the child business component of a link. Continued on next page ParentBusComp SIEBEL SYSTEMS. Always make sure that a business component reference obtained with the ParentBusComp method is valid and is the one expected. When a business component can be the child of more than one business object.Name() == “some name”) { …code here… } Siebel VB Example: If TheApplication.Name = “some name” Then …code here……… End If ActiveBusComp ActiveBusComp returns the business component associated with the active applet.ActiveBusObject.

Continued ParentBusComp Continued If no reference is returned from ParentBusComp. 2004 SIEBEL SCRIPTING BEST PRACTICES Verify Objects Returned.MARCH 23.Name() == “some name”) { ……code…… } Siebel VB Example Set lBC_parent = Me. Therefore. However.ParentBusComp If Not lBC_parent Is Nothing And lBC_Parent. always verify the reference returned when calling ParentBusComp. no error is thrown. the script is verifying that there is a reference before getting the Name attribute.ParentBusComp(). INC. SIEBEL SYSTEMS. EMPLOYEE EDUCATION 38 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . if(lBC_parent != null && lBC_parent.Name = “some name” Then ………code…… End If In this example. calling methods or referencing attributes on a null object will result in a runtime error. eScript Example var lBC_parent = this.

GetFieldValue(<Name>). GetFieldValue(<Name>). As a standalone statement.ActivateField (strFldName) Browser script field is Active if • Id field • Fields visible in the UI Only use ActivateField if an ExecuteQuery statement succeeds it. Updated.MARCH 23. Created By. Created. ActivateField will not implicitly activate a nonactivated field. 2004 SIEBEL SCRIPTING BEST PRACTICES Verify Field is Active before Use Calling GetFieldValue or SetFieldValue on an inactive field may lead to lost data or logic going astray. INC. SIEBEL SYSTEMS. The BC is not queried Correct Use ActivateField(<Name>). Server script field is Active if • System field (Id. EMPLOYEE EDUCATION 39 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Example: Incorrect Use ActivateField(<Name>).⇓Incorrect use! after this. ExecuteQuery(ForwardOnly). ActivateField tells the Siebel application to include this database column in the next SQL statement it executes on the business component which just had a field activated. Updated By) • LinkSpec property on BC set to TRUE • Force Active property on BC set to TRUE • Included in applet definition on active view • Used in calculation of calculated field on active applet • Explicitly activated using BusComp.

lPS_FieldNames. var lPS_FieldNames = TheApplication().SetProperty(“Name".ActivateMultipleFields(lPS_FieldNames). lPS_FieldNames. Java.NewPropertySet(). and the Mobile/ Dedicated Web Client Automation Server. lPS_FieldNames.SetProperty("Account Products". ""). ""). //activate the fields using the property set which has the //field names lbc_account. var ls_project_name.MARCH 23. var ls_agreement_name. ""). C++. INC. CORBA. These methods are best used when accessing Siebel applications through COM. var lPS_FieldValues = TheApplication().SetProperty("Description".NewPropertySet(). ""). //set up the property set which will be used in all three //methods to hold the field names. ""). 2004 SIEBEL SCRIPTING BEST PRACTICES Leverage New Methods in Siebel 7 New Methods ActivateMultipleFields. var ls_account_products. var ls_description. lPS_FieldNames. Using these methods can help reduce redundant lines and make the program more readable. Continued on next page SIEBEL SYSTEMS. Example var lbc_account = this. var ls_name. GetMultipleFieldValues.SetProperty("Project Name". and SetMultipleFieldValues are new methods in Siebel 7. lPS_FieldNames.SetProperty("Agreement Name". EMPLOYEE EDUCATION 40 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .

GetProperty("Project Name").GetMultipleFieldValues(lPS_FieldNames. This method acts sort of like a business //service in that there is an input property set and an output //property set. "All My Products"). //set the field values lbc_account.SetProperty("Agreement Name". The field values will be in the second property set //passed in. "Joey Joe Joe Junior Shabbidoo").FirstRecord()) { //retrieve the values. lPS_FieldNames. = lPS_FieldValues. = lPS_FieldValues.SetProperty("Account Products". ls_agreement_name ls_project_name ls_description ls_name } //now set new values in the property set lPS_FieldNames. 2004 SIEBEL SCRIPTING BEST PRACTICES Leverage New Methods in Siebel 7. lPS_FieldNames. lPS_FieldNames. INC.GetProperty("Description").SetProperty(“Name". lbc_account. //loop through property set to get values. Continued New Methods Continued lbc_account. "This is the description"). //commit the data lbc_account. Continued on next page SIEBEL SYSTEMS. "Siebel Project #2").MARCH 23. = lPS_FieldValues. ls_account_products = lPS_FieldValues.SetProperty("Description". if (lbc_account. "Siebel Agreement").lPS_FieldValues).SetMultipleFieldValues(lPS_FieldNames).WriteRecord().SetProperty("Project Name". lPS_FieldNames.ExecuteQuery(ForwardOnly). } = lPS_FieldValues.GetProperty("Agreement Name"). EMPLOYEE EDUCATION 41 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .GetProperty("Name").GetProperty("Account Products").

Notice the use of SetMultipleFieldValues here. 2004 SIEBEL SCRIPTING BEST PRACTICES Leverage New Methods in Siebel 7.MARCH 23. If you did not use SetMultipleFieldValues. After setting the value using the SetProperty method. If you did not use GetMultipleFields and ActivateMultipleFields. invoke ActivateMultipleFields and the Siebel application passes the property set in as parameter. SIEBEL SYSTEMS. invoke GetMultipleFieldValues to get the field values. you would have to individually set the field values. EMPLOYEE EDUCATION 42 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . INC. the code creates lPS_FieldNames to hold the field names and lPS_FieldValues to hold the field values. you would have to individually activate or get each of the field values. Continued New Methods Continued In this example. After calling the ExecuteQuery method.

GetViewMode SIEBEL SYSTEMS. unexpected behavior can occur. This update has the potential to synchronize back up to the server. For example.MARCH 23. Setting a query to AllView visibility mode gives the user access to all records. This would give the user access to records the user might not need to access. or should not be able to access. a user may have SalesRep visibility on the UI whereas the script will be giving the user All visibility. To avoid this issue. For example. eScript Example: with (bcAcct) { SetViewMode(this. Setting view mode is especially important in an environment with mobile Web client users. such as resetting foreign keys. Siebel VB Example: With bcAcct . INC. EMPLOYEE EDUCATION 43 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .SetViewMode Me. Mobile users have a subset of data in their local databases. which may be different than the view mode of the current view in the UI. causing a data integrity problem. the application may set the Primary ID to No Match Row ID if a child record does not exist on the local database. 2004 SIEBEL SCRIPTING BEST PRACTICES Use Proper View Mode For Queries View mode settings control the formulation of the SQL WHERE clause that the Siebel application sends to the database by using team or position visibility to limit the records available in the business component queried in the script. If you do not set the view mode correctly for limited visibility objects.GetViewMode()). use the GetViewMode method to determine the user’s visibility so that you can apply the same view mode in the query executed by the script.

This is true of search and sort specifications that developers create in script. just as if they created them using configuration. EMPLOYEE EDUCATION . ensure that such specifications cover the key columns of the desirable index. This encourages the database engine to use the index and may prevent unnecessary physical sorts in temporary tables. PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED 44 SIEBEL SYSTEMS. Sorting or searching on non-indexed fields can have detrimental effects on database performance. as well as cover them in the exact index sequence order. especially on large tables. as it produces table scans and temporary tables in the SQL execution plan.SIEBEL SCRIPTING BEST PRACTICES MARCH 23. 2004 Query Only Indexed Columns To assist the database engine in efficiently retrieving and sorting data. INC. For best performance. be sure that search and sort specs reference indexed columns whenever possible.

If you will traverse through the record set from FirstRecord using NextRecord and will not return to a previous record. 2004 SIEBEL SCRIPTING BEST PRACTICES Use ForwardOnly Cursor Mode If you do not specify a cursor mode when querying with Siebel eScript or Siebel VB. This is particularly true if you perform a look up or if you access a pick list. Example: bcAccount.ExecuteQuery(ForwardOnly). improving performance. SIEBEL SYSTEMS. EMPLOYEE EDUCATION 45 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . use ForwardOnly cursor mode. To support this cursor mode.MARCH 23. INC. the system creates a cache to maintain the entire record set. the Siebel application uses the default cursor mode of ForwardBackward. The system will not need to create the cache.

before attempting to retrieve or set a field value for the record.ExecuteQuery(ForwardOnly). Do this even if it seems impossible that a record will not return. NextRecord. always check that a record is returned through the use of FirstRecord. or LastRecord methods.MARCH 23. EMPLOYEE EDUCATION 46 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . 2004 SIEBEL SCRIPTING BEST PRACTICES Verify Existence of Valid Record After Querying When performing a query. Example: bcContact. INC. if (bcContact. sContactId).ClearToQuery(). bcContact.FirstRecord()) { //okay to perform data processing… } SIEBEL SYSTEMS. //Check to see that a record was actually returned //by examining the return of FirstRecord().SetSearchSpec(“Id”. bcContact.

INC. the keyword break is necessary to end a particular case. Using switch or select case statements can frequently compact multiple pages of script into a single page. eScript Example: Instead of Use switch(iNum) If(iNum == 1) { sGrade = ‘A’. Otherwise. the fastest and most readable way of doing this is to use switch (eScript) or select case (Siebel VB). EMPLOYEE EDUCATION 47 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . SIEBEL SYSTEMS. sGrade = ‘B’.MARCH 23. be sure to test all conditions. code falls through to the next case without stopping. Consider using default or case else to hold a default set of behaviors that should occur if none of the stated conditions is met. case 1: else sGrade = ‘A’. not just the most obvious ones. Logic errors can occur in code that does not consider all possible conditions. if(iNum == 3) sGrade = ‘C’. When using switch or select case. 2004 SIEBEL SCRIPTING BEST PRACTICES Use Switch or Select Case Statements When you need to evaluate and compare a single expression with many different possibilities. Reaching the next keyword case will end the previous case. case 2: else sGrade = ‘B’. Siebel VB does not require a break statement. • • It is more efficient because the expression is evaluated once. } Tip: In eScript. case 3: sGrade = ‘C’. then compared to different values. if(iNum ==2) break. break. It is easier to read than a series of nested if…else if statements.

= “second”. if (ls_first == “first”) { ……do something…… } else if (ls_second == “second”) { …………do something else……… } In the example above. the code evaluates two conditions: ls_first and ls_second. not just the most obvious ones. 2004 SIEBEL SCRIPTING BEST PRACTICES Compare the Same Condition In If/Else If Verify that if/else if conditions compare a single expression. Both evaluate to true. but only one condition will execute. EMPLOYEE EDUCATION 48 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . more than one case could be true at the same time. Otherwise.MARCH 23. As with switch and select case. Example: var ls_first var ls_second = “first”. be sure to test all conditions. SIEBEL SYSTEMS. Logic errors may occur in code if you do not consider all possibilities. If/else if blocks evaluate every condition until the first one evaluates to true. but the logic of only the first condition will execute. INC. Then that condition executes and the code ignores the others.

} SIEBEL SYSTEMS. This method automatically and correctly creates new records. Developers. Example: var lBC_mvg = this. frequently try to implement the functionality with many lines of script when a single call to the Associate method will work.GetMVGBusComp(“Sales Rep”). unaware of this method. 2004 SIEBEL SCRIPTING BEST PRACTICES Use the Associate Method to Create Intersection Table Records Use the Associate method to create records in an intersection table. ExecuteQuery(ForwardOnly). with(lBC_associate) { ClearToQuery(). EMPLOYEE EDUCATION 49 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED .GetAssocBusComp(). SomeRowId). SetSearchSpec(“Id”. INC.MARCH 23. if(FirstRecord()) Associate(NewAfter). var lBC_associate = lBC_mvg.

statusList = statusList + bcLOV. as opposed to hard coded values.GetFieldValue("Name"). bcLOV. you can store values in the List Of Values table or other database tables and query for them at runtime. moreRecords = bcLOV. Example: var var var var statusList. if (bcLOV. bcLOV. bcLOV = boLOV.SetSearchSpec("Type". moreRecords = bcLOV.SetSearchSpec("Active". boLOV. Using LookupValue is especially important if you have implemented Multilingual List of Values (MLOV).GetBusObject("List Of Values"). For example."SR_STATUS"). This is particularly important for values that may change often.GetFieldValue("Name"). INC. you can use: TheApplication.ExecuteQuery(ForwardOnly). } PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED 50 SIEBEL SYSTEMS. This is most appropriate when there is only one dynamic value or a short list of values which you need to query for in the script. then concatenated together to form a query filter string.GetBusComp("List Of Values").SIEBEL SCRIPTING BEST PRACTICES MARCH 23. If you need to store multiple LOV values with a common LOV Type.NextRecord(). because you must recompile and redeploy any changes to hard-coded values. bcLOV. or a short list that will fit within one LOV entry.FirstRecord()) { statusList = bcLOV. boLOV = TheApplication(). the LOV values are queried from the List Of Values buscomp. Many commonly used values in scripting are available as process properties which can be obtained with the TheApplication. moreRecords.NextRecord(). if you are writing an error handling script and want to pass the application name. EMPLOYEE EDUCATION .GetProfileAttr("ApplicationName") Alternatively. bcLOV. the script can query directly on the List Of Values business component. wherever possible. 2004 Use Dynamic Values Use dynamic values. bcLOV. while (moreRecords != 0) { statusList = statusList + " OR ". } } else { statusList = ""."Y"). If you have one value. use the LookupValue function to retrieve the value.ClearToQuery(). In the following example.GetProfileAttr() function.

MARCH 23. Also. EMPLOYEE EDUCATION 51 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . future developers reading this script will have to look up what 1 means. Type CursorMode: ViewMode: Logical Constant ForwardBackward ForwardOnly SalesRep View ManagerView PersonalView AllView OrganizationView ContactView GroupView CatalogView SubOrganizationView NewRecordLocation: NewBefore NewAfter NewBeforeCopy NewAfterCopy Value 0 (default) 1 0 1 2 3 5 6 7 8 9 0 (default) 1 2 3 SIEBEL SYSTEMS. 2004 SIEBEL SCRIPTING BEST PRACTICES Use Logical Constants versus Literal Values Always use logical constants where they are available. The above line of code is better implemented as: bc. INC. if Siebel Systems were to change what this literal value does in the NewRecord method in the C++ class. Literal values are prone to upgrade problems as Siebel applications could change the behavior behind a literal value. It makes your code easier to read and easier to upgrade. this code may not behave as expected. These are the most commonly used logical constants and their literal values. Example: bc. Most likely. Using the logical constant alleviates both of these issues.NewRecord(1).NewRecord(NewAfter).

developers have to duplicate this code in many locations. object references are not released unless explicitly written that way. INC. 2004 SIEBEL SCRIPTING BEST PRACTICES Avoid Exit Function and Exit Sub There are two general objections to using Exit Sub or Exit Function in Siebel VB. SIEBEL SYSTEMS. it is difficult to follow the flow of a script with multiple exit points. It is easier to follow and maintain a script with one exit point. When a script exits abruptly. Second.MARCH 23. EMPLOYEE EDUCATION 52 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . First. In methods where there are many exit points. multiple exit points increase the chance of memory leaks from not properly destroying objects.

MARCH 23. as the last statement. SIEBEL SYSTEMS. if the first statement in a script is a GotoView statement. INC. the script holds the statement aside until the entire script executes. Therefore. 2004 SIEBEL SCRIPTING BEST PRACTICES Place GotoView at the End of a Script The GotoView statement does not immediately exit a script and navigate to the specified view. to represent what actually happens. EMPLOYEE EDUCATION 53 PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED . Finally. it is good practice to place GotoView statements at the end of a script. the script executes the method regardless of where it appeared in the script. it will not execute until all other code executes. Rather. For example.

If it is deleting records within a loop. EMPLOYEE EDUCATION . INC. Siebel VB While(BC.FirstRecord <> 0) BC.SIEBEL SCRIPTING BEST PRACTICES MARCH 23. 2004 Use DeleteRecord Method Properly DeleteRecord implicitly moves the record pointer to the next record in the record set. the Siebel application skips every other record.DeleteRecord Wend PROPRIETARY & CONFIDENTIAL DUPLICATION PROHIBITED 54 SIEBEL SYSTEMS. A call to NextRecord after DeleteRecord causes the record pointer to move twice. This means that the Siebel application skips a record in the result set. The following example illustrates the recommended approach for deleting records within a loop.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->