Prototype in Siebel eScript - Part 3

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.

Tags :
Comments powered by Disqus

Related Posts

More Social Capabilities in Zoho CRM

More Social Capabilities in Zoho CRM

I have written about Zoho CRM before, and also about basic capabilities to track social network profiles without any customization.

Read More

Using Apex - Create Task for an Opportunity

Let me be straight for you SFDC configuration vs. coding fanatics - I am in your group.

Read More
Writing trends in Siebel is not bright, find your niche

Writing trends in Siebel is not bright, find your niche

Siebel is not exactly shining, we have seen that before. But, if you are writing about Siebel technology, you should pick up niche topics to get some shine on your blog or website.

Read More