Escript Induction
Escript Induction
Escript Induction
Siebel eScript
Page 1 of 42
eScript
1. Overview........................................................................................................3
2. Declarations..............................................................................................4
3. Statements...................................................................................................5
4. Applet..............................................................................................................10
4.1 Browser Script.................................................................................................10
4.2 Server Script.....................................................................................................12
5. Business Component.....................................................................14
5.1 Browser Script.................................................................................................14
5.2 Server Script.....................................................................................................14
6. Business Service.................................................................................22
6.1 Browser Script.................................................................................................22
6.2 Server Script.....................................................................................................23
7. Common Scenarios.........................................................................25
7.1 Error Handling / User Interaction.................................................................25
7.2 Business Component Operations....................................................................28
7.3 Workflow Invocation from eScripting...........................................................35
7.4 Business Service Invocation from eScripting................................................35
8. Alternatives to Scripting............................................................37
9. References.................................................................................................40
10. Exercises.................................................................................................41
Page 2 of 42
eScript
1.Overview
You should regard coding as a last resort. Siebel Tools provides many ways to configure
your Siebel application without coding, and these methods should be exhausted before
you attempt to write your own code.
Page 3 of 42
eScript
2.Declarations
Siebel eScript is case-sensitive.
A comment is text in a script to be read by users and not by the Siebel eScript
interpreter, which skips over 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.";
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
...
}
Array : An array is a special class of object that holds several values rather than
one. We refer to a single value in an array by using an index number or string
assigned to that value. Types of Array Declaration:
Page 4 of 42
eScript
2) The following line declares a variable ‘b’ as an array with three elements.
var b = new Array(3);
3.Statements
while The while statement executes a particular section of code repeatedly until
an expression evaluates to false.
while(<expression>!=false)
{
<code to be executed>
}
Example:
while (i < 10)
{
i++;
}
For The for statement repeats a series of statements a fixed number of times.
Template:
for ( [var] counter = start; condition; increment )
{
statement_block;
}
Example:
for( var counter = 0;counter<10;counter++)
{
// Array1,Array2,Array3 are array variables.
Array1[counter] = Array2[counter] + Array3[counter];
}
Page 5 of 42
eScript
Example:
if ( i < 10 )
{
TheApplication().RaiseErrorText("i is smaller than 10.");
}
switch The switch statement makes a decision based on the value of a variable
or statement.
Template:
switch( switch_variable )
{
case value1:
statement_block
break;
case value2:
statement_block
break;
. .
.
[default:
statement_block;]
}
Example:
var Alpha = ‘A’;
switch ( Alpha )
{
case 'A':
I=I+1;
break;
case 'B':
I=I+2
break;
default:
I=I+4;
break;
}
Page 6 of 42
eScript
Example:
Try{
AccountBO = TheApplication().GetBusObject("Account");
AccountBC = AccountBO.GetBusComp("Customer BT"); }
Catch(e)
{
TheApplication().RaiseErrorText( "Error: \n", + e.toString()));
}
finally
{
AccountBC = null;
AccountBO = null;
}
Page 7 of 42
eScript
block, so you need to use the object name with its properties
and methods.
The with statement is used to save time when working with
objects. It preppend the object name and a period to each
method used.
Template:
with (object)
{
method1;
method2;
}
Example:
var bcOppty;
var boBusObj;
boBusObj = TheApplication().GetBusObject("Opportunity");
bcOppty = boBusObj.GetBusComp("Opportunity");
var srowid = bcOppty.GetFieldValue("Id");
try
{
with (bcOppty)
{
SetViewMode(SalesRepView);
ActivateField("Sales Stage");
SetSearchSpec("Id", srowid);
ExecuteQuery(ForwardOnly);
}
}
finally
{
boBusObj = null;
bcOppty = null;
}
Page 8 of 42
eScript
break The break statement terminates the innermost loop of for, while, or do
statements. It is also used to control the flow within switch statements.
switch ( key[0] )
{
case 'A':
I=I+1;
break;
case 'B':;
I=I+2;
break;
}
continue The continue statement starts a new iteration of a loop.
The continue statement ends the current iteration of a loop and begins the
next. Any conditional expressions are reevaluated before the loop
reiterates.
The following example writes the numbers 1 through 6 and 8 through 10, followed by
the string .Test
The use of the continue statement after .if (i==7). prevents the write statement for 7,
but keeps executing the loop.
var i = 0;
while (i < 10)
{
i++;
if (i==7)
continue;
document.write(i + ".Test");
}
Page 9 of 42
eScript
4.Applet
{
if(name == 'NewRecord')
{
if(confirm("Are you sure you want to create a new record?"))
return ("ContinueOperation");
else
return ("CancelOperation");
return ("ContinueOperation");
}
catch(e)
{
alert("Error in ChangeFieldValue and error is " + e.toString() + " " +
e.errText());
}
}
Method Name Applet_InvokeMethod
Purpose The InvokeMethod event is triggered by a call to applet.
InvokeMethod or a specialized method, or by a user-defined menu.
Sample Code:
function Applet_InvokeMethod (name, inputPropSet)
{
if (name == "WriteRecord")
{
var nProb = this.BusComp ().GetFieldValue("Primary Revenue Win
Probability");
Page 10 of 42
eScript
Page 11 of 42
eScript
return(CancelOperation);
break;
}
return (ContinueOperation);
}
Page 12 of 42
eScript
Sample Code:
function WebApplet_Load ()
{
try
{
var currBC = this.BusComp();
with (currBC)
{
SetViewMode(OrganizationView);
ClearToQuery();
SetSearchSpec("Last Name", "A*"); // This will restrict the records
on UI to show records with Last Name starting with A.
ExecuteQuery(ForwardBackward);
}
}
catch (e)
{
TheApplication().RaiseErrorText(e.errText);
}
}
Page 13 of 42
eScript
5.Business Component
return (ContinueOperation);
}
Page 14 of 42
eScript
Say you have committed the record with field: Type = “Account” now set the
description field to some value.
catch (exc)
{
TheApplication.RaiseErrorText(exc.errText());
}
finally
{
}
}
Page 15 of 42
eScript
try
{
var sType = “Customer”;
if (FirstRecord())
{
this.SetFieldValue(“LE Code”, “”);
TheApplication().RaiseErrorText(“LE Code already exists”);
return (CancelOperation);
}
}
}
Page 16 of 42
eScript
return (ContinueOperation);
}
Page 17 of 42
eScript
//Check length of asset number search spec - must be longer than 5 chars.
strAssetNum = this.GetSearchSpec("Fault Service Id");
if (strAssetNum != "")
{
if (strAssetNum.length > 0 && strAssetNum.length < 6)
{
TheApplication().RaiseErrorText("Circuit Number must be > 5 char.");
return (CancelOperation);
}
}
}
}
Page 18 of 42
eScript
Page 19 of 42
eScript
Page 20 of 42
eScript
Page 21 of 42
eScript
6.Business Service
Property Sets:
Property set objects are collections of properties, which can be used for storing data.
They may have child property sets assigned to them to form a hierarchical data
structure. A property set is a logical memory structure used primarily for inputs and
outputs to business services.
}
return (“ContinueOperation”);
}
Page 22 of 42
eScript
Page 23 of 42
eScript
if(MethodName=="ValidateOrderLine")
{
CanInvoke="TRUE";
return(CancelOperation);
}
return (ContinueOperation);
}
Page 24 of 42
eScript
7.Common Scenarios
RaiseErrorText
Syntax
TheApplication().RaiseErrorText(value)
OR
TheApplication().RaiseErrorText(value, [arg1], [arg2],...., [argN])
Argument Description
value
Message that you want to display.
Returns
Not applicable
Usage
When invoked, the RaiseErrorText method stops execution of the script.
Example
In the following eScript example, the RaiseErrorText results in a scripting
execution being raised, transferring control to the catch statement. For the
error message to be displayed, the error must be thrown using the throw
statement.
Page 25 of 42
eScript
function BusComp_PreDeleteRecord ()
{
try
{
var status = this.GetFieldValue("Account Status");
if (status == "Gold")
{
TheApplication().RaiseErrorText("Unable to delete Gold
Account");
return (CancelOperation);
}
return (ContinueOperation);
}
catch (e)
{
throw e;
}
}
Used With
Server Script
SWEAlert method
Syntax
TheApplication().SWEAlert(message);
Returns
Undefined (similar to returning nothing)
Usage
Use SWEAlert instead of Alert. With Alert, popup applets such as Mvg
and Pick applets are hidden (sent to the background) when a JavaScript
Alert() is raised by a Browser side event. With SWEAlert, the dialog's
parent applet is not sent to the foreground.
Used With
Browser Script
Page 26 of 42
eScript
Example
The following eScript example displays a status message to the user.
function BusComp_PreSetFieldValue (fieldName, value)
{
Page 27 of 42
eScript
The named fields are analogous to columns in the database table, and the
records are analogous to rows.
Syntax
BusComp.ExecuteQuery ([cursorMode])
Argument Description
Returns
Not applicable
Usage
Page 28 of 42
eScript
When using the ForwardBackward cursor mode, and the query matches
over 10,000 records, the object manager returns this error message: "There
were more rows than could be returned. Please refine your query to bring
back fewer rows."
To reduce the number of queries needed, you can use the parent-child
relationships for business components that are set up in business objects.
For example, an Opportunity business object sets up a parent-child
relationship between the Opportunity business component and the Contact
business component. If you query on the Opportunity business component
you can read values from the corresponding records in the Contact
business component without any additional queries. Before querying a
child business component, you must query its parent, otherwise the query
returns no records.
SetSearchSpec sets the search specification for a particular field. This method
must be called before ExecuteQuery.
Syntax
BusComp.SetSearchSpec(FieldName, searchSpec)
Argument Description
FieldName String containing the name of the field on which to set the search
specification.
Returns
Not applicable
Usage
Page 29 of 42
eScript
Page 30 of 42
eScript
with (bcOppty)
{
SetViewMode (AllView);
// View Mode can be
1. SalesRepView (0)
2. ManagerView (1)
3. PersonalView (2)
4. AllView(3)
5. OrganizationView (5)
6. GroupView (7)
7. CatalogView (8)
8. SubOrganizationView (9)
ActivateField("Sales Stage");
SetSearchSpec("Id", srowid);
//Explore how to make use of SetSearchExpr
ExecuteQuery(ForwardOnly);
if (FirstRecord())
var SalesStage = GetFieldValue(“Sales Stage”);
else
TheApplication().RaiseErrorText(“No Records found”);
}
Page 31 of 42
eScript
Say you are on Opportunities Screen and you want to get Sales Stage
value for some processing.
Get Active BO instance. This would give you the Active BO associated
with the view that you are currently on.
var boBusObj = TheApplication().ActiveBusObject();
GetBusComp instance from Active BO. This would give you the active BC
associated with the applet present in the current view.
var bcOppty = boBusObj.GetBusComp ("Opportunity");
Syntax
BusComp.NewRecord(whereIndicator)
0 (or NewBefore)
1 (or NewAfter)
2 (or NewBeforeCopy)
3 (or NewAfterCopy)
Returns
Not applicable
Page 32 of 42
eScript
Usage
This new row becomes the current row, either before or after the
previously current record, depending on the value you selected for
WhereIndicator.
You can use NewRecord to copy a record. To place the copy before the
original record uses the following command.
BCObject.NewRecord(NewBeforeCopy)
To place the copy after the original record, use the following command.
BCObject.NewRecord(NewAfterCopy)
Example
Say you are on Opportunities Screen and you want to crate new record of
opportunity next to the currently selected record.
var boBusObj = TheApplication().ActiveBusObject();
var bcOppty = boBusObj.GetBusComp("Opportunity");
with (bcOppty)
{
NewRecord(NewAfter);
SetFieldValue(“Sales Stage”, “In Progress”);
.
.
. Likewise set all required fields.
WriteRecord(); // This will commit the record.
}
Page 33 of 42
eScript
NextRecord moves the record pointer to the next record in the business
component, making that the current record and invoking any associated
script events.
Syntax
BusComp.FirstRecord()
BusComp.NextRecord()
Returns
Example
var i = 0;
var isRecord;
while (isRecord)
{
i++;
isRecord = BusComp.NextRecord();
}
Page 34 of 42
eScript
Committing a record:
A commit is performed under the following circumstances:
Page 35 of 42
eScript
Inputs.SetProperty("Id", sId);
.
.Likewise pass all the required inputs by setting Property.
// Pass the Workflow Name as bellow.
Inputs.SetProperty("ProcessName", "MLC Interface Call BT");
Page 36 of 42
eScript
Inputs.SetProperty("Id", sId);
Outputs will be having properties that you are passing from BS. For
Example, If your BS is passing the Sales Stage for Opportunity
Id that you have passed above.
var SaleStage = Outputs.GetProperty(“Sales Stage”);
Page 37 of 42
eScript
8.Alternatives to Scripting.
The following shows alternatives to validating data which do not require the use
of scripting.
Right([Site], 3) = "INN"
11) Is Null/Is Not Null –This field or other fields must or must not have a value
Example: [Name] Is Not Null
Page 38 of 42
eScript
Example: Shipped orders cannot accept changes to the Order Entry – Line
Items records in an existing order
Steps: Create a calculated field, BC Read Only Flag on the Order Entry –
Line Items BC, enter expression such as: IIF([Status] = "Shipped", "Y",
"N")
o Allows field to be referenced in another expression
Create a new Business Component User Property that will determine the
read-only status of a record based on value of a field. Set values
Name: BC Read Only Field
Value: The name of the calculated field to evaluate if the calculated
field's value is true, record is read-only
If BC Read Only Flag contains a TRUE value, then the record is read-only; if it
contains a FALSE value, the record can be edited.
Page 39 of 42
eScript
To enforce a rule stating the child record cannot be changed when the
parent record, Quote, is set to "Approved", configure the Quote.BC Read
Only Flag. In the Quote business component, the BC Read Only Flag field
must an expression that determines if the Status field has the value of
Approved. If so, it returns TRUE, making the child record field read-only.
Name: "Required"
Value expression: IIF([State] Is Not Null, "Y", "N") — An expression that
evaluates to true or false.
Page 40 of 42
eScript
9.References
Page 41 of 42
eScript
10. Exercises
1. User Properties
2. Methods / Events
4. Calling workflow
Page 42 of 42