4 The Arguments Property of a Function The

4 the arguments property of a function the

This preview shows page 31 - 35 out of 334 pages.

TheApplication().RaiseErrorText(global.SumTwo(3, 4)); The Arguments Property of a Function The 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 forth. You can reference the arguments property for a function only in that same function. You can configure a function with an indefinite number of arguments. The following example uses a variable number of arguments and then returns the sum: function SumAll() { var total = 0; for (var ssk = 0; ssk < arguments.length; ssk++) { total += arguments[ssk]; } return total; } About Recursive Functions A 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 that function. If a function calls itself too many times, then the script runs out of memory and aborts. In the following example, to factor a number, the factor function calls itself. 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:
Image of page 31
Siebel eScript Language Reference Version 8.1, Rev. A About Siebel eScript About Functions and Methods 32 function factor(i) //recursive function to print factors of i, {// and return the number of factors in i if ( 2 <= i ) { for ( var test = 2; test <= i; test++ ) { if ( 0 == (i % test) ) { // found a factor, so print this factor then call // factor() recursively to find the next factor return( 1 + factor(i/test) ); } } } // if this point was reached, then factor not found return( 0 ); } Error Checking with Functions If a function fails, then some functions return a special value. Consider the following example: To allow a script to read from or write to a file, the Clib.fopen method opens or creates that file. If the script calls the Clib.fopen method but this method cannot open a file, then the method returns null. If the script then attempts to read from or write to this file, then Siebel CRM creates an error. 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 abort the script and display an error message: var fp = Clib.fopen("myfile.txt", "r"); var fp = Clib.fopen("myfile.txt", "r"); if (null == fp)//make sure null is not returned { TheApplication().RaiseErrorText("Error with fopen as returned null " + "in the following object: " + this.Name() + " " + e.toString() + e.errText()); } For more information, see “Overview of the Clib Object” on page 217 . Where Data Resides Data in a script resides in a literal or in a variable. The following example includes variables and literals: var TestVar = 14; var aString = "test string"; This code does the following:
Image of page 32
About Siebel eScript About Functions and Methods Siebel eScript Language Reference Version 8.1, Rev. A 33 Saves the following literal value to the TestVar variable: 14 Saves the following literal value to the aString variable: test string After you save a literal value in a variable, you can reference that variable anywhere in the script where you declare the variable.
Image of page 33
Siebel eScript Language Reference Version 8.1, Rev. A About Siebel eScript About Functions and Methods 34
Image of page 34
Image of page 35

You've reached the end of your free preview.

Want to read all 334 pages?

  • Summer '16
  • Oracle
  • Type system, Siebel, Siebel eScript

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors