Checking for an empty (Strong Typed) String

This is a follow up article to Checking for an empty String, which was aimed at non typed eScript.

This time around we will look at the pitfalls of string comparison in the ST engine.

I'll assume that you've read the previous article, so i'll jump right into it with this scenario.

//declare vars
var iZero = 0;
var sEmpty:String = "";
var sEmpty2:String = "";

[1st Pitfall]
Before we begin, i'd like to highlight the first pitfall. Since we've declared our variables as a String Object, we can no longer do

if (sEmpty == sEmpty2)
//returns FALSE

Even if we've assigned sEmpty and sEmpty2 the same values, and we trace out the values of both variables, it will look the same, but it will return false.

The reason is sEmpty and sEmpty2 are both pointers to two different objects in memory, so what we are really asking the engine is, are these two objects the same object? Even if they are identical, the answer is No.

[2nd Pitfall]
The correct method of evaluating strings is to use the valueOf or
toString method.

Siebel provides an example of how to perform this in Siebel Support [ID:

if (o1Test.valueOf == o2Test.valueOf)
if (o1Test.toString == o2Test.toString)

Unfortunately, the above examples will always return true regardless of the value of the string.

If you have strong typing enabled in your Tools, type sEmpty followed by the dot and you will get a drop down list of available methods for this object, select the valueOf option, and add the () after it.

This is very important, as explained below
valueOf This returns a pointer to the function
valueOf() This executes the function and returns the value.

So when we use the following expression

if (o1Test.valueOf == o2Test.valueOf)

We are asking the engine, does the function of o1Test.valueOf match the function of o2Test.valueOf? Yes, both functions are the same.

If we used the parenthesis

if (o1Test.valueOf() == o2Test.valueOf())

We are asking does the value of o1Test match the value of o2Test, which is the correct way of executing this. Siebel should default its intellisense to include this parenthesis for function calls.

[Checking if a ST String is empty]

[ST Method 1]

if (sEmpty.valueOf()=="")

[Method 2]

if (sEmpty.length==0)

[ST Method 3]

if (sEmpty.valueOf())

[ST Method 4]

if (sEmpty.valueOf()==="")

If you strong type your string variables, the compiler will give a warning if you try to assign or initialise the number 0 to a string, so you avoid the pitfalls of method 1 & 4 of the T engine.

So what happens if we dynamically assign the string object a number as in the example below?

sEmpty = iZero;//dynamically assign number to ST String

In this scenario, Siebel will not catch it during compile, but it will implicitly convert the number to a string during runtime.

The problem still remains when sEmpty is set to null, because .length, .valueOf will not work on null objects, the workaround for this is similiar to the T Engine. Either initialise your variables or check that the object is not null first.


If we strong type our string we avoid the problem when a Zero is assigned to a string, either Tools will prevent you from compiling the code, or the engine will convert it to a string for you anyway.

But the question on everyone's mind at this point should be, is it recommended to strong type Strings and other primitive variables in the Siebel ST engine?

This article from Ponderproserve provides a good answer on this.

In a nutshell, strong typing primitives will slow down scripting in your application and is not recommended until Siebel fixes this problem.

View last modified log file

Does this look familiar? The good old directory full of log files in your face.

If you spend a lot of time sifting & sorting through log files to find the last modified file for inspection, then this tip might make your day.

I've been searching for a program, that has the following features

* Automatically open the last modified file in a directory
* Provide custom code highlighting
* Real time log viewing
* Cost nothing

Unfortunately, i could not find such a program, but when i was about to give up, i thought of a cheap trick.

I can write a batch file that parses a directory for the last modified file, and open it using my favourite editor/viewer.

Heres how we can achieve it.

Create a batch file with the following contents

@echo off
for /f "tokens=* delims= " %%a in ('dir /b /o:-d C:\Temp\*.log') do (
baretail.exe %%a
goto :eof

Log directory: C:\Temp\
Log file extention: *.log
dir /b: filename only listing
/o:-d: orders by date descending
log viewer: baretail.exe

I know you can just keep a explorer window open, sort your files by date, click refresh, and double click your file, but thats about 4 clicks, including the click to find your window when it loses focus.

Create this shortcut in your taskbar, and you can do it with 1 click, and at the same time, your desk space will be less cluttered, and more memory friendly.

Note: Baretail, is a free real time log viewer that allows custom highlighting. Although it is not freeware, it is a lite version which does not expire.