Siebel Custom Functions in TheApplication
If you want to reuse code in Siebel, one of the common practices is to put it away in the business service and invoke those methods. This way of reusing code, though invaluable for complex operations, can become painful when we have simpler objectives. When I say painful, it applies in some measure for both developers and the execution engine, reasons outlined below:
- Additional business service objects have to be created during execution, this may put some overhead in terms of performance (business service caching kept aside for now)
- Invoking most of the business services requires creation of property sets and calling them in a “proper” way. With the increased lines of code comes the increased complexity
- Developers have to “know” about the business service. This is a big problem in the longer term since code to achieve the same or similar functionality gets scattered in various business services (in-spite of best intentions)
There is an alternate way to use simple reusable code through custom methods on TheApplication object. This uses a basic scripting fact - “all functions written in the application object will be available in any entity and method”. This is easier understood with an example.
Problem #
“I need the value in ‘Description’ field of a specified LOV.”
Though developers swear by LookupValue (and other Lookup) functions, there is little one can do about the 30 (or 50) char limit imposed by the data model. It is common to use ‘Description’ (or some such field) for this purpose. It is again common to see that this is done through a typical BC invocation and query in more than one place.
Solution #
Write a ‘LookupDesc’ function in the application object. Just edit the ‘Siebel Life Sciences’ (or any application) that is being used by your object manager. Create a new function called ‘LookupDesc’ and paste this code:
[code]
function LookupDesc(Type, Value)
{
try {
var sDesc = “”;
var boLOV = TheApplication().GetBusObject(“List Of Values”);
var bcLOV = boLOV.GetBusComp(“List Of Values”);
with (bcLOV) {
ClearToQuery();
SetViewMode(AllView);
ActivateField(“Description”);
SetSearchExpr("[Type]=’" + Type + “’ AND [Value] = ‘” + Value + “’”);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) sDesc = GetFieldValue(“Description”);
} //with
return(sDesc);
}
catch(e) {
throw(e);
}
finally {
bcLOV = null;
boLOV = null;
}
}
[/code]
That is it! You can now call this function from any applet, BC, or Business Service using a single line -
[code]
TheApplication().LookupDesc(“MY_TYPE”, “My Value”)
[/code]
The custom function is also available in ScriptAssist against ‘TheApplication’, which makes things easier a bit.
A note of caution though - don’t overdo this. I would recommend keeping code in the application object simple and tight, and to those functions where lot of reuse is foreseen. Also, note that you have to consider (and potentially introduce this code or variations of it) in all the applications that your Siebel instance uses.