Siebel eScript Language Reference > Using Siebel eScript > Using Operators in Siebel eScript >

Using Logical Operators and Conditional Expressions


Note the following:

  • A logical operator is a type of operator that compares two values, and then determines if the result is true or false. A variable or any other expression can include true or false.
  • A conditional expression is an expression that does a comparison.

You can use a logical operator to make a decision about the statements that reside in a script to run according to how Siebel eScript evaluates a conditional expression.

Table 12 describes the logical operators that you can use in Siebel eScript.

Table 12. Logical Operators That You Can Use in Siebel eScript
Logical Operator
Description

!

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

&&

And. If the value of every expression in the statement is true, then the entire statement is true. For example, if the first expression is false, then Siebel eScript does not evaluate the second expression because the entire expression is false.

||

Or. If the value of one expression in the statement is true, then the entire statement is true. For example, if the first expression is true, then Siebel eScript does not evaluate the second expression because the entire expression is true.

==

Equality. If the values of all expressions in the statement are equal to each other, then the entire statement is true. If the value of one expression is not equal to the value of any other expression, then the entire statement is false.

CAUTION:  The equality operator (==) is different from the assignment operator (=). If you use the assignment operator to test for equality, then your script fails because Siebel eScript assigns the right hand side of the expression to a variable that resides on the left hand side of this expression.

For more information, see Using the Equality Operator with a Strongly Typed Variable.

!=

Inequality. If the value of one expression is different from the value of any other expression, then the entire statement is true. If the value of all expressions in the statement are equal, then the entire statement is false.

<

Less than. If the expression is a < b, and if a is less than b, then the statement is true.

>

Greater than. If the expression is a > b, and if a is greater than b, then the statement is true.

<=

Less than or equal to. If the expression is a <= b, and if a is less than or equal to b, then the statement is true.

>=

Greater than or equal to. If the expression is a >= b, and if a is greater than or equal to b, then the statement is true.

Example of Using Logical Operators and Conditional Expressions

Assume you design a simple guessing game where you configure Siebel CRM to choose a number between 1 and 100, and the user attempts to guess the value of this number. The game provides feedback if the user is correct or if the user answer is higher or lower than the number that the game chooses. The following Siebel eScript code implements this guessing game. Assume that the GetTheGuess function is a custom function that gets the guess:

var guess = GetTheGuess(); //get the user input, which is 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!");
}

In this example, the action that Siebel eScript performs depends on if the value in the parenthesis in an If statement is true or false:

  • True. It runs the statement block that follows this If statement.
  • False. It ignores the statement block that follows this If statement and runs the script that occurs immediately after the statement block.

Using the Equality Operator with a Strongly Typed Variable

If ST eScript code does an equality operation, then it compares different objects depending on the following types of variables that are involved in the comparison:

  • Typeless variable. It compares object values.
  • Strongly typed variable. It compares object identities.

For more information, see Using Strongly Typed and Typeless Variables.

Example of Using the Equality Operator with Strongly Typed Variables

The comparison in the following example involves strongly typed variables. The result is always not equal because Siebel eScript compares object identities in this example. It does not compare 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");

}

Example of Using the Equality Operator with Typeless Variables

The result of the comparison in the following example is always not equal. The variables are typeless. The String is an object and Siebel eScript does object comparisons 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");
}

Making Sure Siebel eScript Compares Variable Values in an Equality Operation

This topic describes how to make sure Siebel eScript compares the values of variables that reside in an equality operation.

To make sure Siebel eScript compares variable values in an equality operation

  • Use the valueOf method.

    For example:

    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 types.

    For example:

    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 © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.