Você está na página 1de 69

Scripting with Siebel

Prerequisites
Developers/Configurators are familiar with Siebel tools and Web Client Application. Knowledge of Java Scripts and Programming Languages like C

What is Scripting
A sequence of statements executed at a Particular Event or when called explicitly.
Advantages: The Siebel Script let you extend data validation beyond what is already provided for in the standard Siebel application. The Siebel Script provides data manipulation capabilities. (Inserting record, deleting record or updating the record)

When should be implemented


Use scripting when you cannot implement the desired functionality by Validation Pre and Post Default Values Required Read Only

Alternatives for Scripting


Do not write script if there is a way to implement the required functionality through configuration. Declarative configuration is easier to maintain and upgrade, leading to a lower total cost of ownership.

Field validation User properties Workflow Personalization Run-time events State model

Replace Script with Declarative Alternatives


For many functional requirements there is a configuration technique available that requires no script. Knowing these configuration techniques, one can make better decisions about whether to write script in the first place.

Example: Field Data Validation


Requirement: Field Validation
if (fieldname == Activation Date) { if(this.GetFieldValue(Expiration Date) != ) { if(this.GetFieldValue(Activation Date) > this.GetFieldValue(Expiration Date)) { throw(Activation Date must be less than Expiration Date, if Expiration Date has been filled in); } } }

Configuration Alternative
Solution: use BC Field Validation Property

Configuration Alternative
Additional properties introduced in Release 8.0
Validation Message with Symbolic String support Message Display Mode

Example: Setting Field Values Based on Field Changes


SetFieldValue event if (fieldname == Product Serialized Flag) { if(this.GetFieldValue(Serial Number) == && this.GetFieldValue(Product Serialized Flag) == Y) { this.SetFieldValue(Serial Number, this.GetFieldValue(Asset Number)); } }

Configuration Alternative
On Field Update Set User Property

Other Siebel Alternatives to Script

State Model

Where is Script Written in Siebel


Application Level Applet Level Business Component Level Business Services (Siebel Tools & Siebel Client)

eScript Programming Basics


Basic eScript Concepts Case,Comments, Identifiers, Variables, Blocks etc Data Types Operators Functions Expressions Statements Commands Object Handling Error Handling

Data Types
Data types in Siebel eScript can be classified into primitive types and object types.

Primitive data type



Chars Float Bool Undefined

A primitive data type is the set of all possible values of a primitive value. A variable that is of a primitive data type is simply a value. The Primitive Data Types are

NOTE: When the chars, float, or bool primitive data types are used to declare variables, they must be used as all lowercase.

Object type:Object types that are built into the scripting engine are: String:A string is written using a pair of either double or single quotation marks, for example: "I am a string" 'so am I' "344" The string "344" is different from the number 344. The first is an array of characters, and the second is a value that may be used in numerical calculations.

Boolean: Siebel eScript implicitly converts values when appropriate, when a Boolean variable is used in a numeric context, its value is converted to 0 if it is false, or 1 if it is true.

Number A Number object is created by using the Number constructor in a new expression

Array
An array is a series of data stored in a variable

Null
The null object is literally a null pointer. The null object type indicates that a variable is empty.

var test = null;

Expressions (Operators)
Numeric Operators String Operators Comparison Operators Logical Operators like +,-,\,MOD etc like &,+ used for string concatenation. like <,>,=,<>,<=,>= like AND,OR,NOT etc

Basic Arithmetic Operators in Siebel

Basic Assignment Arithmetic Operators in Siebel

Examples of assignment arithmetic:


var i; i = 2; //i is now 2 i += 3; //i is now 5 (2 + 3), same as i = i + 3 i -= 3; //i is now 2 (5 - 3), same as i = i _ 3 i *= 5; //i is now 10 (2 * 5), same as i = i * 5 i /= 3; //i is now 3.333...(10 / 3); same as i = i / 3 i = 10; //i is now 10 i %= 3; //i is now 1, (10 mod 3), same as i = i % 3

Logical Operators in Siebel eScript

Siebel eScript statements break Statement continue Statement do...while Statement for Statement for...in Statement goto Statement if Statement switch Statement throw Statement try Statement while Statement with Statement

Siebel eScript Programming Guidelines

Declare your variables. 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 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.

Some eScript Concepts


Case Sensitivity White-Space Characters Comments Variables

Case Sensitivity
Siebel eScript is case sensitive. A variable named testvar is a different variable than one named TestVar, and both of them can exist in a script at the same time. Thus, the following code fragment defines two separate variables:

var testvar = 5; var TestVar = 5;

White Space Characters


White space separates identifiers into separate entities. For example, ab is one variable name, and a b is two. Thus, the fragment

var ab = 2 is valid, but var a b = 2 is not.

Comments
Comments that explain lines of code help users understand the purpose and program flow of a program, making it easier to alter code. There are two formats for comments, end-of-line comments and block comments. End-of-line comments begin with two slash characters, //. Any text after two consecutive slash characters is ignored to the end of the current line. The Siebel eScript interpreter begins interpreting text as code on the next line. Block comments are enclosed within a beginning block comment, /*, and an end of block comment, */. Any text between these markers is a comment, even if the comment extends over multiple lines. Block comments may not be nested within block comments, but end-of-line comments can exist within block comments.

The following code fragments are examples of valid comments:

// this is an end of line comment /* this is a block comment. This is one big comment block. // this comment is okay inside the block. The interpreter ignores it. */ var FavoriteAnimal = "dog"; // except for poodles //This line is a comment but var TestStr = "This line is not a comment.";

Variables
To declare a variable, use the var keyword. To make it local, declare it in a function. var perfectNumber;

A value may be assigned to a variable when it is declared:


var perfetNumber = 28;

Variables
In the following example, a is global to its object because it was declared outside of a function. Typically you declare all global variables in a general declarations section. The variables b, c, and d are local because they are defined within functions. var a = 1; function myFunction() { var b = 1; var d = 3; someFunction(d); } function someFunction(e) { var c = 2 ... }

Web Architecture

Types of Scripting
Browser Scripting Server Scripting

Server Script Architecture

Browser Script Architecture

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, insert, update, and delete operations Access to data beyond the current record

Browser Script Interpreted by IE Browser


Java Script

Server Script Interpreted by the Object Manager


Siebel Visual Basic (Visual Basic syntax) Siebel eScript (Java syntax).

Browser & Server Script can be written


Application Level Applet Level Business Component Level Business Services (Browser Script only Siebel Tools)

Server Scripts:
Server Script executes within the Object Manager so no direct UI interaction is possible. In some cases scripts have to use functionality that is available only on the server side, such as the methods GetBusObject, ExecuteQuery . This can be achieved by writing a server script. Written in Siebel VB (for Windows ) and Siebel eScript (for Windows or UNIX). e.g Business Component Script, Business Service Script, Application Script; and Applet Web Script. Server script use RaiseError, RaiseErrorText, and LookupMessage to pop up messages.

Browser Scripts:
Browser Script executes in and is interpreted by the Browser. If client need to implement functionality in the Browser, this should be done via Browser Script. Some functionalities are available only on the browser (for example, Applet_ChangeRecord Event).For this developer has to write Browser script. Browser Scripts are written in JavaScript. Browser script use Alerts to pop up message box on browser. To generate browser script The utility is called genbscript.exe and may be found in either siebsrvr/bin or client/bin.
For Mobile Client genbscript ENU\uagent.cfg c:\sea703\client\PUBLIC\enu

Siebel Server
genbscript ENU\siebel.cfg c:\sea703\siebsrvr\WEBMASTER ENU Refreshing the Web Server Once the genbscript utility has been run, the Siebel web server must be restarted.

Using the Siebel Script Editor

Adding Scripts to Event Handlers


Enter the script between the predefined beginning and end of the routine

Do not alter the Function, End Function, Sub or End Sub statements A function will return a value, a sub will not Some routines will have an argument list, some will not

Programming Statements
Output Statements Input Statements Arithmetic Statements (Arithmetic Operators) String Manipulations Conditional Statements (Logical & Relational Operators) Loop Statements Database Related Statements

Outputs Statements
A Message to convey to the end user Browser Script
Alert(message)

Server Script
TheApplication.RaiseErrorText Message

Note: RaiseErrorText will cancel the execution of subsequent statements. This should be used when there are no statements to be executed.

Input Statements
To get an Input value from the End-User Browser Script
Name = Prompt (Enter your name: )

Server Script None Note: Use Browser script to accept any input from the user and pass it to the server script.

Conditional Statements
IF statement is commonly used keyword for any scripting language. If Condition returns TRUE, the following statements will be executed. Browser Script (Uses Javascript)
If (condition) { . }

Server Script (Uses eScript or Siebel VB)


If (condition) then . End if
If (condition) { . }

Siebel Visual Basic (it is got Visual Basic syntax)

eScript (it is got Java Syntax)

IF Syntax
Browser Script - Javascript: (Case sensitive) if (a==b) { alert(A is equal to B); } Server Script - Siebel Visual Basic: (Case insensitive) If a=b then TheApplication.RaiseErrorText A is equal to B End if Server Script eScript: (Case sensitive) If (a==b) { TheApplication().RaiseErrorText (A is equal to B); }

IF Syntax (Contd.)
Browser Script - Javascript: (Case sensitive) if (a==b) alert(A is equal to B); else alert (A is not equal to B); Server Script - Siebel Visual Basic: (Case insensitive) If a=b then TheApplication.RaiseErrorText A is equal to B Else TheApplication.RaiseErrorText A Is not equal to B End if Server Script eScript: (Case sensitive) If (a==b) TheApplication().RaiseErrorText (A is equal to B); else TheApplication().RaiseErrorText (A is not equal to B);

Nested If Syntax
Multiple IF conditions are allowed. If (A=B) then If (A=C) then
TheApplication.RaiseErrorText All values are equal

Else
equal

TheApplication.RaiseErrorText Only A and B are

End If Else TheApplication.RaiseErrorText A & B are not equal End If

Loop Statements
While (Condition)
Condition is checked before the statements are executed in the block

Do.Loop (Condition)
First time, all the statements in the block are executed. Condition is checked before getting into the loop.

For variable = 1 to nNext variable


Repeats the loop n times

Database Statements
Database Operations
Query Insert Record Delete Record Field Update Associate child record to Parent Record

Note: Later Slides in the presentation will show how Siebel performs DB operations.

Events - Triggering Point

Object Interface Events


The object interface events are available in Server Script or Browser Script within Siebel Tools.
Application Events Applet Events Business Component Events Business Service Events

Levels at which Scripting is done


Application Level Applet Level Business Component Level Business Service Level Application Events & Methods
Events like Application_Start Application_Close TheApplication.ActiveBusObject TheApplication.ActiveBusComp TheApplication.LoginName TheApplication.GotoView

Methods like

Applet Events & Methods


Events like Applet_ChangeFieldValue Applet_ChangeRecord WebApplet_Load WebApplet_PreCanInvokeMethod 3 Called before the PreInvokeMethod,determines whether or not the user has the authority to invoke the Applet method. Applet_InvokeMethod

Methods like

Business Component Events & Methods


Events like BusComp_ChangeRecord BusComp_DeleteRecord BusComp_WriteRecord BusComp_Query BusComp_InvokeMethod BusComp.ActivateField(FieldName) BusComp.ClearToQuery BusComp.ExecuteQuery BusComp.GetFieldValue BusComp.SetFieldValue BusComp.NewRecord BusComp.DeleteRecord

Applet.BusObject Applet.BusComp Applet.InvokeMethod Applet.Name

Methods like

Business Service Events & Methods


Events like Service_InvokeMethod Service_PreInvokeMethod Service_PreCanInvokeMethod Service.GetProperty(propName) Service.SetProperty(propName, propValue)

Methods like

Object Handling
Declare variable Get the Object handler Clear the query Activate the Field (activate fields which is required to be used for processing) Set the Sort Spec (by default it is ASCENDING) Execute Query (ForwardOnly & ForwardBackward) Clear the object handler and release the memory.

In eScript, destroy an object by setting it to null (oBC = null). In Siebel VB, destroy an object by setting it to nothing (Set oBC = Nothing). Release objects in the reverse order in which the Siebel application created them; child objects first, parent objects second.
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

Place Code in the Correct Event Handler


One of the most common issues identified during script reviews is the inappropriate use of object events. Placing code in the wrong event Handler can lead to altered data and may negatively impact performance.
Do not use Siebel application Pre- events (such as PreQuery, PreSetFieldValue, and PreWriteRecord) to manipulate data in objects other than the one hosting the script.

The companion events, such as Query, SetFieldValue, and WriteRecord, occur after the internal and field-level validations succeed, and therefore are the appropriate events for such manipulation. For example, the WriteRecord event fires after the record writes successfully. When this event fires, you know that the record exists; therefore it is safe to create or modify data in other objects, without fearing orphaned records or an inconsistent state of the application.

BusComp_PreSetFieldValue : Field level validation BusComp_PreWriteRecord : Record level validation

BusComp_SetFieldValue
BusComp_WriteRecord activities

: Field triggered actions


: Record triggered actions

Example: synchronizing two business components or creating


BusComp_PreQuery :Code control over SearchSpecs

Error Handling in eScript


Implement eScript error handling through the try/catch/finally mechanism. Try block: contains the logic that you want performed. Catch block: captures the error. Finally block: performs any cleanup work such as destroying object references.

Example:

function illustrateErrorHandling() { try { /*The try block encompasses all statements that could cause an exception. */ ...executable code goes here... }//end try The try keyword precedes a block of normal processing code that may throw an exception.

Practical - 1
Creating Custom Buttons to Control User Navigation

Button on an Applet
Edit the Web Layout of the Applet Select the mode of the Applet (Base or Edit or Edit List) Drag & Drop the button from the Web Controls toolbar on the Applet where placeholder is available.

X denotes empty placeholders

Standard methods are:

Specify the Method to be Invoked

For Custom method, type the name of the method in Method Invoked Property of the button.
Caption = Title Method Invoked = AcceptRecord Name = AcceptBtn

Save the Applet and close the Wed Layout editor.

Enable the button


To enable a button the WebApplet_PreCanInvokeMethod event must be scripted to set its parameter to TRUE.

Add Script in Browser Script


Save the Applet and close the script editor.
Note: Server methods can also be called instead of browser script. Place code in BusComp_PreInvokeMethod BC event or WebApplet_PreInvokeMethod event

Browser Script Compiler folder

Used to specify the folder where bscripts\all resides. This is the folder where Browser Scripts are generated during compilation

Execute GenBScript to generate Browser Script if it is not generated during compilation

Syntax: Genbscript j:\Siebel\7.7\web client\bin\enu\uagent.cfg j:\Siebel\7.7\web client\public\enu ENU

Click on the Applet


Compile the Applet Execute the Siebel Web Client Navigate to the view where applet was modified to hold the button with title Accept. The Browser Script should display an alert box indicating Hello ! I am in AcceptRecord "

Você também pode gostar