Wednesday, December 8, 2010

Siebel Scripting Best Practices

Dead Code

Remove redundant or never called code

Remove commented code

Remove inactive code

Remove empty methods

Helps easy maintenance and reduces confusion for developers who maintain the script


Scope of  Variables

Use always smallest possible scope of variables

It is better to declare and use objects where they are needed and pass them as parameters to other methods

It is difficult to understand the scope or state of global variables because they are instantiated in one method
and accessed in othere

Shared Globals Vs Profile Attributes

Shared global variables ( SetSharedGlobal / GetSharedGlobal ) achieve the same results as the profile attributes ( SetProfileAttr / GetProfileAttr ) , the profile attributes can also be referred to within configuration  ( eg : in calculated fields ) and as well as workflow

Avoid TheApplication().SetSharedGlobal().Instead use getProfileAttr().

Destroy Objects

Memory leaks

Destroy objects such as business components , business objects , business services , property sets etc before leaving the method

Destroy child objects before parent

Destroy Pick / Assoc / MVG business components before the parent business component

Destroy business components before business objects

Business services and property sets can be destroyed in any order

Hard coding of Values

Avoid Hard coding of Values.Instead use LookUp methods

Cursor Mode

Use ForwardOnly cursor mode

Defualt cursor mode is ForwardBackward

Eg:- BC_Contact.ExecuteQuery(ForwardOnly )

This allows records to be processed in a sequence hence giving best performance

Use of this instead of ActiveBusObject , ActiveBusComp

Calling ActiveBusObject and  ActiveBusComp only makes sense if used in a script running in the application object or in a business service.Scripr running in an applet or in a business component should use :

this.BusObject()

this.BusComp()

this.BusComp().ParentBusComp()

All Custom Scripts inside PreInvoke Method

Most of the times we see developers writing the entire script written in the PreInvoke method itself.The PreInvoke method is  instantiated and allocated in the computer memory when invoked.Because all the custom script ( custom methods ) are written in one common place it may be possible that more lines of code than the one would be executed will also be allocated in the memory which may cause a performance problem

It is recommended to split the script into functions for each method and call the corresponding  function from the PreInvoke method

Use of Active

The application properties "ActiveBusObject' and 'ActiveBusComp' should not be used to instantiate objects.They can be used however to check which object is currently active.These properties can be useful when writing scripts that may be called from multiple areas within the application , and may require different processing dependant on the source of the call

Use of Switch

You should use a 'Switch' in cases where a variable needs to be tested against multiple values.This should be used instead of multiple if.else.statements for the sake of clarity

No comments:

Post a Comment