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");
}

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");
}

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"); 
}