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();
nCount = 0;
//...SetSearchSpec("Last Name","Singh");
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
while (isRec)
{
nCount++;
isRec = NextRecord();
}
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();
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())
{
}
}
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 :