Siebel eScript Language Reference > Siebel eScript Language Overview > Operators in Siebel eScript >

Logical Operators and Conditional Expressions in Siebel eScript


Logical operators compare two values and evaluate whether the resulting expression is false or true. A variable or any other expression may be false or true. An expression that performs a comparison is called a conditional expression.

Logical operators are used to make decisions about which statements in a script are executed, based on how a conditional expression evaluates.

The logical operators available in Siebel eScript are described in Table 11.

Table 11. Logical Operators in Siebel eScript
Operator
Purpose
Description

!

Not

Reverse of an expression. If (a+b) is true, then !(a+b) is false.

&&

And

True if, and only if, both expressions are true. Because both expressions must be true for the statement as a whole to be true, if the first expression is false, there is no need to evaluate the second expression, because the whole expression is false.

||

Or

True if either expression is true. Because only one of the expressions in the or statement needs to be true for the expression to evaluate as true, if the first expression evaluates as true, the Siebel eScript interpreter returns true and does not evaluate the second.

==

Equality

True if the values are equal; otherwise false. Do not confuse the equality operator, ==, with the assignment operator, =.

!=

Inequality

True if the values are not equal; otherwise false.

<

Less than

The expression a < b is true if a is less than b.

>

Greater than

The expression a > b is true if a is greater than b.

<=

Less than or equal to

The expression a <= b is true if a is less than or equal to b.

>=

Greater than or equal to

The expression a >= b is true if a is greater than b.

For example, if you were designing a simple guessing game, you might instruct the computer to select a number between 1 and 100, and you would try to guess what it is. The computer tells you whether you are right and whether your guess is higher or lower than the target number.

This procedure uses the if statement, which is introduced in the next section. If the conditional expression in the parenthesis following an if statement is true, the statement block following the if statement is executed. If the conditional expression is false, the statement block is ignored, and the computer continues executing the script at the next statement after the ignored block.

The script implementing this simple guessing game might have a structure similar to the one that follows, in which GetTheGuess() is a function that obtains your guess.

var guess = GetTheGuess(); //get the user input, either 1, 2, or 3
target_number = 2;
if (guess > target_number)
{
   TheApplication().RaiseErrorText("Guess is too high.");
}
if (guess < target_number)
{
   TheApplication().RaiseErrorText("Guess is too low.");
}
if (guess == target_number);
{
   TheApplication().RaiseErrorText("You guessed the number!");
}

This example is simple, but it illustrates how logical operators can be used to make decisions in Siebel eScript.

CAUTION:  Remember that the assignment operator, =, is different from the equality operator, ==. If you use the assignment operator when you want to test for equality, your script fails because the Siebel eScript interpreter cannot differentiate between operators by context. Using the assignment operator incorrectly is a common mistake, even among experienced programmers.

Using the Equality Operator with Strongly Typed Variables

The ST eScript engine compares object values when performing equality comparisons for typeless variables but it compares object identities when performing equality comparisons for strongly typed variables.

The following script examples illustrate the different results produced from eScript comparison operations using the equality operator.

The result of the comparison in the following script, which involves strongly typed variables, is always "not equal" because object identities are being compared, not object values:

function foo ()
{
var oStr1 : String = new String ("aa");
var oStr2 : String = new String ("aa");
if (oStr1 == oStr2)
TheApplication ().RaiseErrorText ("equal");
else
TheApplication ().RaiseErrorText ("not equal");

}

However, the result of the comparison in the following script is also always "not equal", even though the variables are not strongly typed. This is because the String is an object, and object comparisons are used in the if statement.

function foo ()
{
var oStr1 = new String ("aa");
var oStr2 = new String ("aa");
if (oStr1 == oStr2)
TheApplication ().RaiseErrorText ("equal");
else
TheApplication ().RaiseErrorText ("no equal");
}

To ensure that the values of the variables are compared in an equality comparison operation, you can either:

  • Use the valueOf () method, as shown in the following script:

    function foo ()
    {
    var oStr1 = new String ("aa");
    var oStr2 = new String ("aa");
    if (oStr1.valueOf () == oStr2.valueOf ())
    TheApplication ().RaiseErrorText ("equal");
    else
    TheApplication ().RaiseErrorText ("no equal");
    }

  • Use primitive data type variables, as shown in the following script:

    function foo ()
    {
    var oStr1 : chars = "aa"
    var oStr2 : chars = "aa";
    if (oStr1 == oStr2)
    TheApplication ().RaiseErrorText ("equal");
    else
    TheApplication ().RaiseErrorText ("no equal");
    }

Siebel eScript Language Reference Copyright © 2007, Oracle. All rights reserved.