Skip to main content
  1. Posts/

Prototype in Siebel eScript - Part 3

·3 mins

In earlier examples, we saw how prototype in Siebel eScript can be put to use. We extend that here by using prototype together with script libraries and user defined objects.

Problem #

I want to ’look up’ the description of a LOV provided I have its type and value.

Solution #

We address the problem in two steps:

  • Define a user object and make sure it is available for the session. One of the common ways of doing this is in Application object
  • Use the custom object to define a prototype for useful function(s) - in our case ‘LookupDesc’

The ‘how to do it’ part is also in two steps:

Step 1: Define a variable in the application script #

We will consider ‘Siebel Life Sciences’ application as an example.

Application: Siebel Life Sciences | (declarations)

var MyApp;

And, call a business service where MyApp is initialized. This is just to keep the code clean in the application object, it works just fine even if you code within that object itself.

Application: Siebel Life Sciences | Method: Application_Start

function Application_Start(CommandLine) {
  var bsStarter = TheApplication().GetService("COG Test Proto");
  bsStarter.Init();
}

Step 2: Write the custom business service ‘COG Test Proto’ #

Service: COG Test Proto | Method: Init

function Init() {
  TheApplication().MyApp = new MyAppFun();
  MyAppFun.prototype.LookupDesc = LookupDescFun;
}

Service: COG Test Proto | Method: MyAppFun

function MyAppFun() {
  // this is a dummy, but funny function.
}

Service: COG Test Proto | Method: MyAppFun

function LookupDescFun(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;
  }
}

That’s about it, now MyApp is ready to have some fun. Again, we write a quick service to test how things work.

Service: COG Test Proto Call | Method: Service_PreInvokeMethod

function Service_PreInvokeMethod(MethodName, Inputs, Outputs) {
  Outputs.SetProperty("out", TheApplication().MyApp.LookupDesc("blah", "blah"));
}

Theory & Explanation #

  1. MyApp is defined as a variable in Application object, the same is initialized in a business service. It does not matter what the function [MyAppFun] contains, we will not be using that anyway
  2. The prototype LookupDesc is defined as an extension of MyAppFun. Any object based on MyAppFun will have access to the LookupDesc functionality
  3. We invoke LookupDesc as an extension of the variable in the application object. There are others out there who just use TheApplication = MyApp, but that practice is not encouraged
  4. When TheApplication().MyApp.LookupDesc is invoked, Siebel will look for the LookupDesc function for MyApp object. Since the functionality does not exist OOB, the prototype is consulted and in turn LookupDescFun function is executed.

Keep in mind that this is just an example, more complex functions coded this way can easily scale and promote reuse.