Asynchronous Business Service Invocation in Siebel Open UI

With Innovation Pack 2013, the Siebel Open UI API provides the possibility to invoke business service methods (and methods in general) asynchronously.



This is documented (here too) and my friend Neel from Siebel Unleashed was the first to blog about this exciting feature.

Today I would like to share with you how I put this new feature to good use. Do you remember the "Sortable Screen Tabs" series from last summer (has it really been one year already)?

Recently, I was revisiting the code and the way it invoked the business service which modifies the Tab Layout data. This is the "original" code to instantiate and invoke the service.

var oSvc = SiebelApp.S_App.GetService("AHA Tab Layout Service");
var inPS = SiebelApp.S_App.NewPropertySet();
var outPS = SiebelApp.S_App.NewPropertySet();
inPS.SetProperty("sTabs", tabarray.toString());
outPS = oSvc.InvokeMethod("SetTabLayout", inPS);

When I look at the above code today, I must confess it is pretty traditional. The code wouldn't be any different in a browser script from 2002, and even in eScript, the concept is the same albeit with some minor differences.

My latest code version looks like this:

var oSvc = SiebelApp.S_App.GetService("AHA Tab Layout Service");
var inPS = SiebelApp.S_App.NewPropertySet();
inPS.SetProperty("sTabs", arrTabs.toString());
//nothing new until here, but where's the output PS?
if(oSvc){
   var config = {async:true,scope:this,selfbusy:true};
   //wait a minute, what's this?
   oSvc.InvokeMethod("SetTabLayout", iPS, config); //but how?
}

Needless to say, it still works but the user can continue to work even while the business service is still running. The new and exciting stuff is the configuration object which we can use to pass runtime information to the Open UI proxy layer which sends the AJAX request to the server.

This config object has the following properties (Bookshelf documentation here):

  • async: this is the magic one. When set to true, the invocation will be done asynchronously, allowing us to continue with the remaining code immediately. When set to false, we will have to wait (synchronous invocation) until the service returns.
  • scope: set to 'this' always (so says bookshelf).
  • selfbusy: display the 'busy cursor' on the screen (false) or not (true).

As you can see I used the above properties in my code to invoke the business service method asynchronously without displaying a 'busy cursor' so end users do not notice anything.

Call Back Later

But the goodness does not stop here. My example business service does not return anything. But what if you have to pick up the output property set and process it? Clap your hands for the callback functions.

Let's have a look at the following config object:

var config = {};
config.async = true;
config.scope = this;
config.cb = function(){
   var outPS = arguments[2];
   if (outPS!== null){
      //parse output property set
}

The cb ('callback') property defines a function which will be invoked when the method invocation is complete. For business service method invocations we can pick the output property set from the arguments array (it's the third array item, hence the [2] index).

And there's even more...

For error handling, use the errcb property (similar to cb) to specify a function which will be invoked when the AJAX call fails.

The documentation also mentions an opdecode property but is pretty stumm about what it does exactly (decode or not decode the AJAX reply).

Finally, there's the mask property which (when selfbusy is set to false) allows us to control the screen masking during the method invocation.

Summary

Applet methods, business service methods, you name it. The Siebel Open UI framework is truly innovative and allows developers to gain complete control over what happens when.

have a nice day

@lex

תגובות

פוסטים פופולריים מהבלוג הזה

FINS Data Transfer Utilities

SBL-BPR-00191: The rowId of the active row of the primary buscomp '%1', '%2', does not match the Primary Id

Profile Attributes and Open UI