A few tricks with setTimeout()

Vertex a quite well known reader of Siebel Unleashed has shared with a really interesting and useful article. This is a must read for everybody who is into Siebel configuration.


There is one function that, if used properly, could do some nice stuff on user interface. This function name is setTimeout() and it 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.

I’ll show you two ways of using this function, which are both implemented in our app.

Auto refreshing applet:

Let’s say we have a requirement to refresh certain list applet every couple seconds or so. Our shipment manager is rather lazy and is not particularly fond of manual and tedious requerying of pending shipments list applet 🙂

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 cool 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");
else
oMyControl.SetProperty ("FontColor", "#FF0000");
setTimeout ("Flash()", 200)
}
}

And to invoke this function for the first time:

function Applet_Load ()
{
Flash();
}

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.


Thanks a lot Vertex for such a wonderful article

3 Responses to A few tricks with setTimeout()

  1. Good article, but does it work for Server scripts as well?, can i use this against a buscomp events?
    As an Example, refresh a applet until the child record is updated?,

    • Yes it works but it is a bit tricky. There is no entry in Siebel Tools because this is a standard java script function not a siebel function. Siebel doesn’t officially supports it.

      You have to make sure that FindControl is returning you an object instance… try using alert after every line and see where it is failing..

Leave a Reply

Contribute