Tuesday, January 24, 2012

A few tricks with setTimeout() in Siebel

setTimeout() allows you to execute a browser script at some point in the future.

It takes two parameters:
  •  a function to call
  •  time to wait in milliseconds.
Auto refreshing applet:

Let’s say we have a requirement to refresh certain list applet every couple seconds or so. To reach this goal we might use setTimeout() to refresh the applet at equal intervals.

Open Browser Script editor on your applet and create a function:

function Refresh()
var oMyApplet = theApplication().FindApplet ("Your_Applet_Here");
if (oMyApplet) {
oMyApplet.InvokeMethod ("RefreshBusComp");
setTimeout ("Refresh()", 5000);

This function will find your applet and refresh it. It will also schedule itself to be reinvoked in 5 seconds.
The only thing left is to call this function for the first time. A perfect place to do it – Applet_Load event.

function Applet_Load ()
setTimeout ("Refresh()", 5000)

Flashing control/label:

Assume the requirement: draw user attention to a critical field if it has invalid or questionable data.
One way to do this is by making the field flashing red for example. 

We’ll start with creating our main function

(Browser Script):

function Flash()
var oMyApplet = theApplication().FindApplet ("Your_Applet_Here ");
if (oMyApplet) {
var oMyControl = oMyApplet.FindControl ("Your_Control_Here");
if (oMyControl.GetProperty ("FontColor") == "#FF0000")
oMyControl.SetProperty ("FontColor", "#000000");
oMyControl.SetProperty ("FontColor", "#FF0000");
setTimeout ("Flash()", 200)

And to invoke this function for the first time:

function Applet_Load ()

This way the field will flash red 2.5 times a second. You may enhance the script by adding data validation or even use gradient transition .

You might as well flash the control’s label rather than the text. In order to do so you will have to add a control user property useLabelID with value TRUE and use oMyControl.SetLabelProperty instead of oMyControl.SetProperty.

1 comment: