Bookshelf Home | Contents | Index | PDF |
Siebel eScript Language Reference > About Siebel eScript > About Functions and MethodsA function is an independent section of code that does the following:
It begins with the following statement: It ends with the following statement: You use the same format as you use with a variable to name a custom function. You can write code that uses any valid variable name as a function name. It is recommended that you use a name that describes the work that the function performs. You can write code that calls a function repeatedly from various objects or script. It is similar to a subroutine. To call a function, you must know what information the function requires as input and what information it provides as output. This book describes the predefined functions that come with Siebel eScript. You can write code that uses these functions any time you use the Siebel eScript interpreter. You can write code that uses a function anywhere that you can use a variable. To use a function, you do the following:
A Siebel VB method is a function that is part of an object or class. It can include a predefined procedure that you can use to call a function that does an action or a service for an object. A Siebel VB statement is a complete instruction. For more information, see Passing a Value to a Function. Example of a FunctionThe TheApplication.RaiseErrorText function is an example of a function that allows you to display formatted text if an error occurs. It does the following work:
About Function ScopeA function is global. Siebel eScript can call it from anywhere in a script in the object where you declare it. The examples in this topic achieve the following results:
Example of Calling a Function as a FunctionThe following example calls the SumTwo function: function SumTwo(a, b) Example of Using a Method to Call a FunctionThe following example uses a method of the global object to call the SumTwo function: function SumTwo(a, b) The Arguments Property of a FunctionThe arguments property of a function is a list of the arguments that Siebel eScript passes to the function. The first argument is arguments[0], the second argument is arguments[1], and so on. You can write code that references the arguments property for a function only in that same function. You can configure a function that includes an indefinite number of arguments. The following example uses a variable number of arguments, and then returns the sum: function SumAll()
About Recursive FunctionsA recursive function is a type of function that calls itself or that calls another function that calls the first function. Siebel eScript allows recursion. Each call to a function is independent of any other call to this function. If a function calls itself too many times, then the script runs out of memory and aborts. In the following example, the factor function calls itself so that it can factor a number. Factoring is an appropriate use of recursion because it is a repetitive process where the result of one factor uses the same rules to factor the next result: function factor(i) //recursive function to print factors of i, Error Checking with FunctionsIf a function fails, then some functions return a special value. Consider the following example:
To prevent this error, you can use the following code to determine if Clib.fopen returns null when it attempts to open a file. If it does return null, then you can write code that aborts the script and displays an error message: var fp = Clib.fopen("myfile.txt", "r"); For more information, see Overview of the Clib Object. Where Data ResidesData in a script resides in a literal or in a variable. The following example includes variables and literals: var TestVar = 14;
After you save a literal value in a variable, you can reference this variable anywhere in the script where you declare the variable. |
Siebel eScript Language Reference | Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices. | |