Siebel eScript Language Reference > Methods Reference > Data Querying Methods >

Function Object


A Function object contains the definition of a function that you define in Siebel eScript. It returns the code that you configure this function to return. For more information, see Return Statement of a Function Object.

Format A

function funcName( [arg1 [, ..., argn]] )
{
     body
}

In format A you declare a function, and then call it in your code. It is the standard way to define a function.

Format B

var funcName = new Function([arg1 [, ..., argn,]] body );

In format B you explicitly create a function. If you use format B to create a function object, then Siebel CRM evaluates it each time it uses this function. This configuration is not as efficient as format A because Siebel CRM compiles a declared function only one time instead of evaluating it every time it uses the function.

Arguments

Table 103 describes the arguments for a function object.

Table 103. Arguments of a Function
Argument
Description

funcName

The name of the function.

arg1 [, ..., argn]

An optional list of arguments that the function accepts.

body

The lines of code that the function runs.

Example 1

The following example uses format A to declare a function named AddTwoNumbers. It uses AddTwoNumbers as the name of the function:

function AddTwoNumbers (a, b)
{
   return (a + b);
}

Example 2

The following example uses format B to create a function named AddTwoNumbers. It uses the Function constructor to create a variable named AddTwoNumbers. The value of this variable is a reference to the function that the Function constructor creates:

AddTwoNumbers = new Function ("a", "b", "return (a + b)");

Length Property of a Function Object

The length property returns the number of arguments that the function expects.

Format

funcName.length

Table 104 describes the arguments for the length property.

Table 104. Arguments for the Length Property
Argument
Description

funcName

The name of the function that the length property uses to return the number of arguments.

Return Statement of a Function Object

The Return statement passes a value back to the function that called it.

Format

return value

Table 105 describes the arguments for the Return statement.

Table 105. Arguments for the Return Statement
Argument
Description

value

Contains a value from the function that calls the Return statement.

Usage

Siebel CRM does not run any code in a function that occurs after a Return statement.

If you define a return type for a custom function, then you must explicitly return a value of the same type that the function header specifies. All control paths must lead to a Return statement.

Example 1

The function in the following example returns a value that is equal to the number that Siebel CRM passes to it multiplied by 2, and then divided by 5:

function DoubleAndDivideBy5(a)
{
   return (a*2)/5
}

Example 2

The following example does the following work:

  • Uses the value from the function in Example 1
  • Calculates the following expression:

    n = (10 * 2) / 5 + (20 * 2) / 5

  • Displays the value for n, which is 12:

    function myFunction()
    {
       var a = DoubleAndDivideBy5(10);
       var b = DoubleAndDivideBy5(20);
       TheApplication().RaiseErrorText(a + b);
    }

Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.