Escript Induction

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 42

eScript

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

Siebel eScript is a scripting or programming language that application developers use to


write simple scripts to extend Siebel applications.

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.";

 Variables in Siebel eScript may be either global or local. 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 perfectNumber = 28;

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:

1 )The following line declares a variable ‘a’ as an array with no elements.


Parenthesis are optional in case of no parameters. Hence both the following
lines are equivalent
var a = new Array();
var a = new Array;

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) We can also pass the elements to the array function.


var c = new Array(5, 4, 3, 2, 1, 0);

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

if The if statement tests a condition and proceeds depending on the result.


if ( condition)
{
statement_block;
}

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

try...catch…finally The try statement is used to process exceptions that occur


during script execution. When you want to trap potential
errors generated by a block of code, place that code in a try
statement, and follow the try statement with a catch statement.
The catch statement is used to process the exceptions that
may occur. The finally clause is used for code that should
always be executed before exiting the try statement,
regardless of whether the catch clause halts the execution of
the script
Template:
try
{
statement_block
}
catch (Exc)
{
exception_handling_block
throw (Exc) // to pass the exception object to the calling function.
}
finally
{
statement_block_2
// You can include object destruction here.
//Example, OptyBC = null;

Example:
Try{

AccountBO = TheApplication().GetBusObject("Account");
AccountBC = AccountBO.GetBusComp("Customer BT"); }
Catch(e)
{
TheApplication().RaiseErrorText( "Error: \n", + e.toString()));
}
finally
{
AccountBC = null;
AccountBO = null;
}

with The with statement assigns a default object to a statement

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

The portion in the with block is equivalent to:


bcOppty.SetViewMode(SalesRepView);
bcOppty.ActivateField( "Sales Stage" );
bcOppty.SetSearchSpec("Id", srowid);
bcOppty.ExecuteQuery(ForwardOnly);

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

4.1 Browser Script


Method Name Applet_PreInvokeMethod
Purpose The PreInvokeMethod event is called before a specialized method is
invoked, by a user-defined applet menu, or by calling InvokeMethod
on an applet.
Sample Code:
function Applet_PreInvokeMethod (name, inputPropSet)
{
   try

   {
   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");

if (Prob >= 30)


{
theApplication().SetProfileAttr ("gsDoHandoff", "false");
alert(theApplication().GetProfileAttr ("gsDoHandoff"));
//Explore ProfileAttributes.
}
}

Page 10 of 42
eScript

Method Name Applet_ChangeRecord


Purpose The ChangeRecord event is called when the user moves to a different
row or view.
Sample Code:
function Applet_ChangeRecord ()
{
   try
   {
      var thisBC = this.BusComp();
      var sFlag = thisBC.GetFieldValue("Primary Revenue Committed Flag");
      if (sFlag == "Y")
      {
       alert("This record cannot be updated ");
      }
   }
   catch(e)
   {
    alert("Error in ChangeFieldValue and error is " + e.toString() + " " +
e.errText());
   }
}
Method Name Applet_Load
Purpose The Load event is triggered after an applet has loaded and after data is
displayed
Sample Code:
function Applet_Load ()
{
Try
{
// Reset the gsDoHandoff flag
alert("Executing Applet Load method.");
}
catch (e)
{
// Error checking is slightly redundant for this trivial script
e = null;
}
}

Page 11 of 42
eScript

4.2 Server Script

Method Name WebApplet_ PreCanInvokeMethod


Purpose The PreCanInvokeMethod event is called before the PreInvokeMethod,
allowing the developer to determine whether or not the user has the
authority to invoke the Applet method.
Sample Code:
You have added a button on Opportunity List applet. The method invoked on click
of that button is “CustomMethod” [Control property]. The following script will
enable the button.

function WebApplet_ PreCanInvokeMethod (MethodName,&CanInvoke)


{
   switch (MethodName)
   {
   case "CustomMethod":

CanInvoke = “True”; // If you set it to false the button will be


disabled.
      return(CancelOperation);
      break;
   }
   return (ContinueOperation);
}

Method Name WebApplet_PreInvokeMethod


Purpose The PreInvokeMethod event is called before a specialized method for
the Web applet is invoked or a user-defined method is invoked through
oWebApplet.InvokeMethod.
Sample Code:
// On click of a button, you want to update the current record. This has to be done
in PreInvokeMethod of the applet. Hence, all you’re processing should happen here.
function WebApplet_PreInvokeMethod (MethodName)
{
   switch (MethodName)
   {
   case "CustomMethod":

//Update Status to “Booked”.


this.BusComp().SetFieldValue(“Status”,”Booked”);
this.BusComp().WriteRecord();

      return(CancelOperation);
      break;
   }
   return (ContinueOperation);
}

Page 12 of 42
eScript

Method Name WebApplet_InvokeMethod


Purpose The InvokeMethod() event is called after a specialized
method or a user-defined method on the Web applet has
been executed.
Sample Code:
function WebApplet_InvokeMethod (MethodName)
{
try
{
if (MethodName=="CustomMethod")
{
// The control comes here from PreInvoke Method.
// If you open the siebel application in debug mode, the
Status value should be “Booked”.
Var NewStatus = this.BusComp().GetFieldValue(“Status”);
}
}
}

Method Name WebApplet_Load


Purpose The WebApplet_Load () event is triggered just after an
applet is loaded.

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

5.1 Browser Script


Method Name BusComp_PreSetFieldValue
Purpose The PreSetFieldValue event is called each time a field is to be
changed or populated for a given business component. In Browser
Script mainly this event is used for Field validation.
Sample Code:
When Order Line Sub Status field value = Cancelled and Product is SMPF then,
make the Cancellation Reason field mandatory.
function BusComp_PreSetFieldValue (fieldName, value)
{
if((fieldName == "Order Line Sub Status") &&( value == "Cancelled"))
{
if (this.GetFieldValue("Product")=="SMPF")
{
if (!this.GetFieldValue("Cancellation Reason"))
{
theApplication().SWEAlert("Cancellation Reason is Mandatory Field");
return ("CancelOperation");
}
}
}
return ("ContinueOperation");
}

5.2 Server Script


Method Name BusComp_PreSetFieldValue
Purpose The PreSetFieldValue() event is called before a value is
pushed down into the business component from the user
interface or through a call to SetFieldValue. The control comes
here just before committing the record into the database.
Sample Code:
When Order Line Sub Status is Cancelled then, auto set BES Status field to
Cancelled.
function BusComp_PreSetFieldValue (FieldName, FieldValue)
{

if (FieldName == "Order Line Sub Status" && FieldValue =="Cancelled")


{
this.SetFieldValue("BES Status","Cancelled");
}

return (ContinueOperation);
}

Page 14 of 42
eScript

Method Name BusComp_SetFieldValue


Purpose The SetFieldValue () event is called when a value is pushed down into the
business component from the user interface or
through a call to SetFieldValue. The control comes here just after the record
is commited into the database.
Sample Code:

Say you have committed the record with field: Type = “Account” now set the
description field to some value.

function BusComp_SetFieldValue (FieldName)


{
   if (FieldName == "Type" && GetFieldValue(FieldName) == "Account")
   {
      SetFieldValue("Description", "Record is of Type 'Account'." );
   }
}

Method Name BusComp_NewRecord


Purpose
The NewRecord event is called after a new row has been created in the
business component and that row has been made active. The event may be
used to set up default values for Fields.
Sample Code:
Wherever a new Opportunity Record is created, set default Priority to Low.
function BusComp_NewRecord ()
{
try
{
this.SetFieldValue(“Priority”, “Low”);
//this here references the current BusComp instance.
return (ContinueOperation);
}

catch (exc)
{
TheApplication.RaiseErrorText(exc.errText());
}

finally
{
}
}

Page 15 of 42
eScript

Method Name BusComp_PreWriteRecord


Purpose The PreWriteRecord() event is called just before a row is written into
the database. The event may perform any final validation necessary
before the actual save occurs.
Sample Code:
function BusComp_PreWriteRecord ()
{
//Checking the same Legal Entity Code is existing in One Siebel

try
{
var sType = “Customer”;

var boAccount = TheApplication().GetBusObject(“Account”);


var bcCustomer = boAccount.GetBusComp(“Customer BT”);

var LECode = this.GetFieldValue(“LE Code”);


if(LECode != “”)
{
with (bcCustomer)
{
ActivateField(“LE Code”);
ActivateField(“Type”);
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec(“Type”, sType);
SetSearchSpec(“LE Code”, LECode);
SetSearchSpec(“Id”, “ <> “ + this.GetFieldValue(“Id”));
ExecuteQuery(ForwardOnly);

if (FirstRecord())
{
this.SetFieldValue(“LE Code”, “”);
TheApplication().RaiseErrorText(“LE Code already exists”);
return (CancelOperation);
}
}
}

Page 16 of 42
eScript

Method Name BusComp_WriteRecord


Purpose The WriteRecord event is called just after a row is committed into the
database.
Sample Code:
function BusComp_WriteRecord ()
{
try
{ // Legal Entity Exist Flag Updation
if (this.GetFieldValue("Account Status")=="Active")
{
this.ParentBusComp().ActivateField("Legal Entity Exist Flag");
this.ParentBusComp().SetFieldValue("Legal Entity Exist Flag","Y");
this.ParentBusComp().WriteRecord();
}
}
catch (exc)
{
// log error message
// Cleanup variables
}

Method Name BusComp_ChangeRecord


Purpose The ChangeRecord() event is called when a business component
changes its current record from one record to another, for example when
a user changes the record focus in an applet or when a script calls the
NextRecord() method.
Sample Code:
If Status = Preparation then, Agreed Bid Submission Date is mandatory.
function BusComp_ChangeRecord ()
{
var sstatus = this.GetFieldValue("Status");
if (sstatus == "Preparation")
{
if (this.GetFieldValue("Agreed Bid Submission Date") == "")
TheApplication().RaiseErrorText("Date cannot be blank");
return(CancelOperation);
}

return (ContinueOperation);
}

Page 17 of 42
eScript

Method Name BusComp_PreQuery


Purpose The PreQuery() event is called before query execution.
Sample Code:
function BusComp_PreQuery ()
{
try
{
var strAssetNum = "";

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

Method Name BusComp_Query


Purpose The Query() event is called just after the query is completed
and the rows have been retrieved but before the rows are
actually displayed.
Sample Code:
If the current view is "GS New Opportunity View BT" then, query operation not allowed.
function BusComp_Query ()
{
if(TheApplication().ActiveViewName() == "GS New Opportunity View BT")
{
TheApplication().RaiseErrorText ("You cannot run queries from
this Screen. ");
return(CancelOperation);
}

Page 18 of 42
eScript

Method Name BusComp_PreInvokeMethod


Purpose The PreInvokeMethod() event is called before a specialized
method is invoked on the business component.
Sample Code:
Click of the button added above triggers CustomMethod. If CancelOperation was not done
on Applet Methods, the control would come here.
function BusComp_PreInvokeMethod (MethodName)
{
if (MethodName == "CustomMethod")
{
// Your code here.
return (CancelOperation);
}
return (ContinueOperation);
}
Method Name BusComp_InvokeMethod
Purpose The InvokeMethod() event is called when the InvokeMethod
method is called on a business component.
Sample Code:
<Need Sample Code >

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.

6.1 Browser Script

Method Name Service_PreInvokeMethod


Purpose The PreInvokeMethod event is called before a
specialized method on the business service is invoked.

If implementing a new method, or overriding the


behavior of a method implemented in a specialized
business service, the script should return
CancelOperation to avoid invoking an “Unknown
method name” error.
Sample Code:
function Service_PreInvokeMethod (methodName, inputPropSet,
outputPropSet)
{
switch(methodName)
{
case “UpdateData”:
UpdateData(inputPropSet, outputPropSet);
return (“CancelOperation”);
break;
case “UpdateBESActivity”:
UpdateBESActivity(inputPropSet, outputPropSet);
return (“CancelOperation”);
break;
case “AddNotesToBES”:
AddNotesToBES(inputPropSet, outputPropSet);
return (“CancelOperation”);
break;
default:
return(“ContinueOperation”);
break;

}
return (“ContinueOperation”);
}

Page 22 of 42
eScript

Method Name Service_InvokeMethod


Purpose The InvokeMethod event is called after the
InvokeMethod method is called on a business service.

Service_InvokeMethod is rarely scripted, but can be used


for such post-operation events as posting a notice to a log
when the event completes successfully.

Method Name Service_PreCanInvokeMethod


Purpose
The PreCanInvokeMethod event is called before the
PreInvokeMethod, allowing the developer to determine
whether or not the user has the authority to invoke the
business service method.

6.2 Server Script

Method Name Service_PreInvokeMethod


Purpose The PreInvokeMethod event is called before a
specialized method on the business service is invoked.

If implementing a new method, or overriding the


behavior of a method implemented in a specialized
business service, the script should return
CancelOperation to avoid invoking an “Unknown
method name” error.
Sample Code:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == “UpdateDataLI”) //UD: OMS:1796 –ROC Automation
{
UpdateDataLI(Inputs, Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}

Method Name Service_InvokeMethod


Purpose The InvokeMethod event is called after the
InvokeMethod method is called on a business service.

Service_InvokeMethod is rarely scripted, but can be used


for such post-operation events as posting a notice to a log
when the event completes successfully.

Page 23 of 42
eScript

Method Name Service_PreCanInvokeMethod


Purpose
The PreCanInvokeMethod event is called before the
PreInvokeMethod, allowing the developer to determine
whether or not the user has the authority to invoke the
business service method.
Sample Code:
function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
if(MethodName=="ValidateOrderHeader")
{
CanInvoke="TRUE";
return(CancelOperation);
}

if(MethodName=="ValidateOrderLine")
{
CanInvoke="TRUE";
return(CancelOperation);
}

return (ContinueOperation);
}

Page 24 of 42
eScript

7.Common Scenarios

7.1 Error Handling / User Interaction

 RaiseErrorText

The RaiseErrorText method raises a scripting error message to the browser.


The error text is the specified literal string. The optional arguments are used to
format the string if it contains any substitution arguments (%1, %2).

Syntax
TheApplication().RaiseErrorText(value)
OR
TheApplication().RaiseErrorText(value, [arg1], [arg2],...., [argN])

Argument Description
value
Message that you want to display.

arg1, arg2, ... argN


Optional arguments used to format the error message if it contains any
substitution arguments (%1, %2).

Returns
Not applicable

Usage
When invoked, the RaiseErrorText method stops execution of the script.

Internally, the RaiseErrorText methods raise a Server Script exception.


Therefore, if you have implemented error handling in your scripts, the
error handling can suppress RaiseErrorText functionality.

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

SWEAlert displays a dialog box containing a message to the user.

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)
{

if (fieldName == "Account Status")


{
var cVolume = this.GetFieldValue("Current Volume");

if ((value == "Inactive") && (cVolume > 0))


{
TheApplication().SWEAlert("Unable to inactivate an account
that has a current volume greater than 0");
return ("CancelOperation");
}
}
return ("ContinueOperation");
}

Page 27 of 42
eScript

7.2 Business Component Operations

 The Siebel business component object (BusComp) presents a two-


dimensional grid of data values much like a table in a relational database.

 The named fields are analogous to columns in the database table, and the
records are analogous to rows.

 Querying for Records

ExecuteQuery returns a set of BusComp records using the criteria established


with methods such as SetSearchSpec.

Syntax

BusComp.ExecuteQuery ([cursorMode])

Argument Description

An integer. An optional argument that must be one of the following


cursorMode constants (provided in Siebel VB as well as COM Servers):

 ForwardBackward. Selected records can be processed from first to


last or from last to first. This is the default if no value is specified.

 ForwardOnly. Selected records can be processed only from the first


record to the last record. Focus cannot return to a record.

Returns

Not applicable

Usage

Use a cursorMode of ForwardOnly wherever possible to achieve


maximum performance. If you use ForwardOnly, make sure that your
application code does not attempt to navigate backward using
PreviousRecord or FirstRecord without a requery. Do not use
ForwardOnly when operating on UI business components unless the
application code requeries using a cursorMode of ForwardBackward.

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.

searchSpec String containing the search specification.

Returns

Not applicable

Usage

If ClearToQuery is not called before SetSearchSpec, the business


component performs a logical AND on the new search specification and
the existing search specification. The maximum length of a predefined
query is 2000 characters. Do not use SetSearchExpr and SetSearchSpec
together, they are mutually exclusive.

Page 29 of 42
eScript

 SetSearchSpec: Explore how to use this.

Page 30 of 42
eScript

Querying on a new instance of BC.

To get the Sales Stage for a given Opportunity Id.


var boBusObj = TheApplication().GetBusObject("Opportunity");
var bcOppty = boBusObj.GetBusComp("Opportunity");

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

// Variable destructions should be done in finally block of try


catch.
bcOppty = null;
boBusObj = null;

Page 31 of 42
eScript

 Querying on active instance of BC.

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");

You can do a GetFieldValue directly without querying, provided that field


is exposed on UI or Force Active is set for that field.
For Example,
var SalesStage = bcOppty .GetFieldValue(“Sales Stage”);

// Variable destructions should be done in finally block of try catch


section.
bcOppty = null;
boBusObj = null;

 Creating new record:


NewRecord adds a new record (row) to the business component.

Syntax
BusComp.NewRecord(whereIndicator)

whereIndicator: Predefined constant or corresponding integer


indicating where the new row is added. This value should be one of the
following:

 0 (or NewBefore)
 1 (or NewAfter)
 2 (or NewBeforeCopy)
 3 (or NewAfterCopy)

It is recommended to use Predefined constant rather than numbers.

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

// Variable destructions should be done in finally block of try


catch section.
bcOppty = null;
boBusObj = null;

Page 33 of 42
eScript

 Navigating between records in a BC instance:

 FirstRecord and NextRecord Method

FirstRecord moves the record pointer to the first record in a business


component, making that record current and invoking any associated script
events.

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

FirstRecord: A Boolean True if records found else False

NextRecord: A Boolean True if next record present else False

Example

It counts the total number of opportunity records in Opportunity


business component.

var i = 0;
var isRecord;

var boBusObj = TheApplication().GetBusObject("Opportunity");


var bcOppty = boBusObj.GetBusComp("Opportunity");
with (bcOppty)
{
    ClearToQuery();
    SetViewMode (AllView);
//Observe no search spec given. As you have put clear
to query, this query fetches all the records present
for Opportunity.
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
}

while (isRecord)
{
   i++;
   isRecord = BusComp.NextRecord();
}

Page 34 of 42
eScript

// i will hold the count.

 Committing a record:
A commit is performed under the following circumstances:

 Explicitly by issuing BusComp.WriteRecord


 Navigating away from the current record by any of the following
methods:
o BusComp.NextRecord
o BusComp.PreviousRecord
o BusComp.FirstRecord
o BusComp.DeleteRecord (DeleteRecord commits
automatically, because it moves the cursor to another
record.)
o BusComp.LastRecord
 Closing a BusComp (Set BusComp = Nothing) Query / Update /
Insert / Delete

Page 35 of 42
eScript

7.3 Workflow Invocation from eScripting.

 From Server Script.


var sId = ‘ABC’; // RowId that you want to pass to BS.

// Create Process Input and Output PropertySets.


var Inputs = appObj.NewPropertySet();
var Outputs = appObj.NewPropertySet();

//Create object instance for “Workflow Process Manager”.


var WorkFlowSvc = TheApplication().GetService("Workflow Process
Manager");

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");

//Invoke the workflow.


WorkFlowSvc.InvokeMethod("RunProcess", Inputs, Outputs);

// Outputs will be having properties that you are passing from


// workflow.

For Example, If your workflow is passing the Sales Stage for


Opportunity Id that you have passed above.
var SaleStage = Outputs.GetProperty(“Sales Stage”);

Sales Stage – a Process Property declared in your WF.

 From Browser Script:


var sId = ‘ABC’; // RowId that you want to pass to BS.

var Inputs = theApplication().NewPropertySet();


var Outputs = theApplication().NewPropertySet();

var svc = theApplication().GetService("Workflow Process Manager");

Inputs.SetProperty ("Id", sId);


Inputs.SetProperty("ProcessName", "MLC Interface Call BT");
Outputs = svcValidate.InvokeMethod("RunProcess", Inputs);

7.4 Business Service Invocation from eScripting.

 From Server Script.


var sId = ‘ABC’; // RowId that you want to pass to BS.

// Create Process Input and Output PropertySets.


var Inputs = appObj.NewPropertySet();
var Outputs = appObj.NewPropertySet();

Page 36 of 42
eScript

//Create object instance for Business Service that you want to


invoke.
var BusinessSvc = TheApplication().GetService("<BS Name here>");

Inputs.SetProperty("Id", sId);

.Likewise pass all the required inputs by setting Property.


//Invoke the business service method..
BusinessSvc.InvokeMethod("<Method Name here>", Inputs, Outputs);

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”);

 From Browser Script:


var sId = ‘ABC’; // RowId that you want to pass to BS.
var Outputs = theApplication().NewPropertySet();
var Inputs = theApplication().NewPropertySet();

var svc = theApplication().GetService("Order Entry - Order


Validation BT");

Inputs.SetProperty ("Id", sId);


Outputs = svcValidate.InvokeMethod("ValidateOrderHeader", Inputs);

Page 37 of 42
eScript

8.Alternatives to Scripting.
The following shows alternatives to validating data which do not require the use
of scripting.

Validation Field Property


The Validation field property allows for common Visual Basic expressions and
comparison operators to be use, which ensures flexibility.
1) Validation Field uses common VB expressions Left(), Right(), Len() etc.
Example: If the last three characters for the Site field must be the text
INN, enter this syntax in the Validation property of the Site field to verify
that fact

Right([Site], 3) = "INN"

2) Validation Field uses comparison operators >,<,<=,>=, and so on


Example: If the Start Date must come before or on the date specified in the End Date
field, enter this in the Validation property for the Start Date field <= [End Date]

3) Today() – Today's date Example: > Today() – 1

4) ParentFieldValue() – Field value in a parent BC. Validations based on field values in a


parent BC Example: <> ParentFieldValue("Name")

5) LookUpValue() – Looks up a value in the List of Values. Allows values in List of


Values table to be used in validations
Example: = LookupValue ("PROD_CD", "Training")

6) PositionName() – Returns the Position Name Example:<> PositionName()

7 PositionId() – Returns the Position Id. PositionId() returns row


Example: = PositionId()

8) Parent:BCName.Field – Same as ParentFieldValue(), except specifying a specific


business component and field may be necessary when BC can be child of different
parents
Example: <> Parent: 'Account.Name'

9) LoginName() – Returns Login Name for currently logged in user


Example: <> LoginName()

10) NOT – Negation. Identical to <>


Example: NOT ([Name and Location])

11) Is Null/Is Not Null –This field or other fields must or must not have a value
Example: [Name] Is Not Null

Business Component User Properties

Page 38 of 42
eScript

 Business requirement: Do not change record based on value entered by the


user in a field
o Declarative alternative: Use BC Read Only Field property
o Rule: Do NOT allow editing of record when Order Status field set to
"Shipped"

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.

 Business requirement: Update field based on value entered in another field


o Declarative alternative: Use the On Field Update Set X
business component user property
Example: The Update Status field based on value entered by user in
Description field for Service Request
Steps: Add new Business Component User Property to the Service Request BC
Name: On Field Update Set
Value: "Description", "Status", "Working"

 Business requirement: Disallow changes to child record if parent Quote


record has a certain status
o Declarative alternative: Configure using Business Component User
Property: Parent Read Only field
o Rule: When parent record field is set to a specific value, the child record
cannot be changed

Example: Quote Items cannot be changed if quote status is set to


"Approved"

Steps: Choose the child or grandchild business component, which should


become read-only and add new business component user property with these
properties
Name: Parent Read Only Field
Value:<bcname>.<bcfield>

Example Quote.BC Read Only Flag

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.

 Business requirement: Based on value in one field, value is required in


another field
o Declarative alternative: Use Field User Property called Required to
dynamically make the field required based on an expression
o Rule: If a value has been entered in one field, another field value is
required to complete the information
Example: If State field has value, Country Code is required One field is
dependent on another. To set the Required Field User Property, add a user
property to the Country field in the appropriate business component

Name: "Required"
Value expression: IIF([State] Is Not Null, "Y", "N") — An expression that
evaluates to true or false.

 Business requirement: Field is made read-only based on value found in


another field in same record in same business component. Will make target
field read-only based on value in another field
o Declarative alternative: Use BC User Property Field Read Only: <Field
Name>
o BC User Property takes field to make read-only as an argument
o Specifies field to test in same business component for True or False
value in its Value property
Example: Only certain positions can change an account's name

1) Add calculated field to the Account business component


Name: Account Name Read Only Flag
Calculated: True
Calculated Value: IIf (PositionName()) = "Siebel Administrator", "N", "Y")
Type: DTYPE_BOOL

2) Add business component user property


Name: Field Read Only:Account Name
Value: Account Name Read Only Flag

Page 40 of 42
eScript

9.References

Siebel eScript guide


OneSiebel Coding Standards
Performance Guidelines
Declarative Alternatives to Scripting

Page 41 of 42
eScript

10. Exercises

1. User Properties

2. Methods / Events

3. Data Validatons using scripting

4. Calling workflow

Page 42 of 42

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy