Siebel Scripting Best Practices : Part 1

1/14/2011 No Comment

This article discusses Siebel Scripting Best Practices.

Siebel Scripting best practices in developing applications with Siebel Tools. 

Siebel Scripting is used to accomplish some functionality which cannot be achieved by general Siebel Configuration. However, Scripting is one of the main reasons for giving rise to performance problems in Siebel Applications. If you need to write code write a Business Service to increase modularity.

1. Try to avoid multiple queries within the code if only one query can be used.
I am providing below a simple example, the following code will get the email address of the contact on a Opportunity: 

var boOpty;
var bcOpty;
var boCon;
var bcCon;
var sConEmail = "";
try
{
boOpty = TheApplication().GetBusObject("Opportunity");
bcOpty = boOpty.GetBusComp("Opportunity");
boCon = TheApplication().GetBusObject("Contact");
bcCon = boCon.GetBusComp("Contact");
with (bcOpty)
{
ActivateField("Opportunity Number");
ActivateField("Contact Id");
ClearToQuery();
SetSearchSpec("Opportunity Number","abc123");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
bcCon.ActivateField("Email Address");
bcCon.ClearToQuery();
bcCon.SetSearchSpec("Id", GetFieldValue("Contact Id"));
bcCon.ExecuteQuery(ForwardOnly);
if (bcCon.FirstRecord())
{
sConEmail = bcCon.GetFieldValue("Email Address");
}
}
}
}
catch(e)
{TheApplication().RaiseErrorText(e.toString());
}
finally
{
bcCon = null;
boCon = null;
bcOpty = null;
boOpty = null;
}
However, there is no need to query on Contact Business Component separately because there already exists a join to the Contact Email field:

var boOpty;
var bcOpty;
var sConEmail = "";
try {
boSR = TheApplication().GetBusObject("Opportunity");
bcSR = boSR.GetBusComp("Opportunity");
with (bcSR)
{
ActivateField("Opportunity Number");
ActivateField("Contact Email");
ClearToQuery();
SetSearchSpec("Opportunity Number","abc123");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
sConEmail = bcCon.GetFieldValue("Contact Address");
}
}
}
catch(e)
{
TheApplication().RaiseErrorText(e.toString());
}
finally{
bcOpty = null;
boOpty = null;
}
2. If there is a profile attribute or shared global variables are used to control code flow then ensure that these are reset as timely as possible. 

For instance, lets say that you set a profile attribute on the BusComp_NewRecord event script to flag that a Contact record has been created:

TheApplication().SetProfileAttr("NEW_CONTACT","Y");
Now you want to execute code on the BusComp_WriteRecord event script only if it is a new Contact. The code shows that the check is made that the profile attribute is set, then it is immediately reset. If the profile attribute reset code is placed after the code processing there is no way to guarantee it will be reset as that code may error and go to the catch. 

To be completely sure the reset of the profile attribute can be placed in the finally block, this will guarantee reset whenever the BusComp_WriteRecord event code is executed.

try {
if (TheApplication().GetProfileAttr("NEW_CONTACT") == "Y")
{
TheApplication().SetProfileAttr("NEW_CONTACT","");
//...then continue processing}
//....}
catch(e)
{
TheApplication().RaiseErrorText(e.toString());
}
finally{
TheApplication().SetProfileAttr("NEW_CONTACT","");
}
3. Please make sure that while loops with delete record do not include NextRecord. If you use ExecuteQuery and then need to scroll through each record in the result set you would use logic such as this:

ExecuteQuery(ForwardOnly)
isRecord = FirstRecord();
while (isRecord)
{
//...do your processingisRecord = NextRecord();
}
However, if you were to perform a DeleteRecord in the processing within the while loop you would not want to use NextRecord to go to the next record,  because DeleteRecord will automatically place the cursor on the next record, if you used NextRecord it would skip the current record. Therefore the code should look like as cited below.

ExecuteQuery(ForwardOnly)
isRecord = FirstRecord();
while (isRecord)
{
isRecord = DeleteRecord();
//do not use: isRecord = NextRecord();}
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