Siebel Scripting Best Practices : Part 2

1/14/2011 No Comment

Siebel scripting best practices.

Try using CountRecords() than looping through recordset.
We often see while loops used to obtain the count of records in a record set. CountRecords() function can do this instead of looping.

CountRecords script:
SetSearchSpec("Last Name","Singh");
ExecuteQuery(ForwardOnly);
nCount = CountRecords();
While loop to get the record count
nCount = 0;
//...SetSearchSpec("Last Name","Singh");
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
while (isRec)
{
nCount++;
isRec = NextRecord();
}
It is always better to call a function from an event script in Siebel
If you write script on Siebel Business Component or Applet event methods, you are better off creating a function and calling that function from the event script.
This is due to the following reasons.
a) If you need to declare objects, these will be declared in the function and not in the event script. hence, this will prevent declaration every time the event method is called and rather only when you need to call the function.
b) You should only call the function when required, if you call the function every time the event is fired this could have serious performance issues.

Be cautious with Global variables within a BC
If you declare a variable in the declaration section of a Business Component server script, this variable will be made available to all event methods on the BC. However, if you use a variable with the same name in a business service and the business service instantiates the business component, will in turn invoke the BC event methods, as such it will cause the variable used in the business service to become undefined.

This is best explained with an example.
On Contact BC, defined a variable in the (declarations) server script section called strContactId:
var strContactId;
On Contact BC PreQuery event method you can include the following code as below

var sSearchExpr;
sSearchExpr = this.GetSearchExpr();
Now you can write a business service that performs a query on Contact BC using a variable strConId as cited below.

var strConId;
var bo;
var bc;
strConId = "0-1";
bo = TheApplication().GetBusObject("Contact");
bc = bo.GetBusComp("Contact");
with (bc)
{
ClearToQuery();
SearchSearchExpr("[Id] = '" + strConId + "'");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
}
}
You can set a break-point on Contact PreQuery script and in Siebel Tools debug mode, execute the business service. The BS correctly defines the search expression to be: [Id] = '0-1'. When the ExecuteQuery is fired, the Contact BC PreQuery script is invoked, you will find that the value of this.GetSearchExpr is now [Id] = 'undefined'.

The main problem is that the global variable in Contact BC interferes with the local variable defined in the business service, because they have got the same name.

Therefore it is advisable to try and avoid declaring variables in the (declarations) section of a Business Component server script.
Related Posts


No comments :

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer