34
Siebel Scripting, Siebel Scripting, Part Two Part Two eScript Syntax eScript Syntax

Siebel Scripting 3

Embed Size (px)

Citation preview

Page 1: Siebel Scripting 3

Siebel Scripting, Part Siebel Scripting, Part TwoTwo

eScript SyntaxeScript Syntax

Page 2: Siebel Scripting 3

IntroductionIntroduction

Data TypesData TypesDeclaring VariablesDeclaring VariablesOperatorsOperatorsDecisionsDecisionsLoopingLoopingFunctionsFunctionsArrays in eScriptArrays in eScriptSome Important eScript MethodsSome Important eScript MethodsUsing Siebel ObjectsUsing Siebel Objects

Page 3: Siebel Scripting 3

Comments in eScriptComments in eScript

Use two forward slashes // at the Use two forward slashes // at the front of a line to make a single line front of a line to make a single line commentcomment

Example:Example://This is a single line comment//This is a single line comment

Use /* to start and */ to end a Use /* to start and */ to end a multi-line commentmulti-line comment

Example:Example:/* This Comment/* This Comment

stretches over stretches over multiple lines */multiple lines */

Page 4: Siebel Scripting 3

Data TypesData Types

There ARE no data types in eScriptThere ARE no data types in eScripteScript is a eScript is a loose typedloose typed language languageVariables can change type Variables can change type

dynamicallydynamicallyeScript is Case SensitiveeScript is Case Sensitivevar MyString and var mystring are var MyString and var mystring are

two DIFFERENT variables!two DIFFERENT variables!

Page 5: Siebel Scripting 3

OperatorsOperators

Mathematical OperatorsMathematical Operators+, -, *, /, % (no exponentiation)+, -, *, /, % (no exponentiation)

Conditional OperatorsConditional Operators==, !=, <, >, <=, >===, !=, <, >, <=, >=

Logical OperatorsLogical Operators&&, ||, !&&, ||, !

AssignmentAssignment==

TernaryTernaryCondition ? Do If True : Do If FalseCondition ? Do If True : Do If False

Page 6: Siebel Scripting 3

Declaring VariablesDeclaring Variables

Syntax:Syntax: var VarName; var VarName;

Examples:Examples: var iScore;var iScore; var bcContact;var bcContact;

Can declare more than one variable of the Can declare more than one variable of the same type in one line:same type in one line: var sLastName, sFirstName;var sLastName, sFirstName;

eScript Variables can be initialized:eScript Variables can be initialized: var sName = “Charlie”;var sName = “Charlie”; var iCount = 1;var iCount = 1;

Page 7: Siebel Scripting 3

Decisions: ifDecisions: if

Syntax:Syntax: if (Condition)if (Condition) {{

‘‘Code to be executed if Condition is TrueCode to be executed if Condition is True }}

Example:Example: if (iScore < 60)if (iScore < 60) {{

sGrade = “Fail”;sGrade = “Fail”; }}

Simple Decision Making ConstructSimple Decision Making Construct

Page 8: Siebel Scripting 3

Decisions: else Decisions: else Syntax:Syntax:

if (Condition)if (Condition){{

‘‘Code to Execute if Condition is TrueCode to Execute if Condition is True}}elseelse{{

‘‘Code to Execute if Condition is FalseCode to Execute if Condition is False}}

Page 9: Siebel Scripting 3

Decisions: elseDecisions: else

Example:Example:if (iScore < 60)if (iScore < 60){{

sGrade = “Fail”;sGrade = “Fail”;}}elseelse{{

sGrade = “Passing”;sGrade = “Passing”;}}

Page 10: Siebel Scripting 3

Decisions: elseifDecisions: elseif

Example:Example: if (iScore < 60)if (iScore < 60) {{

sGrade = “Fail”;sGrade = “Fail”; }} elseif (iScore >= 100)elseif (iScore >= 100) {{

sGrade = “Perfect”;sGrade = “Perfect”; }} elseelse {{

sGrade = “Passing”;sGrade = “Passing”; };};

Page 11: Siebel Scripting 3

Decisions: switch caseDecisions: switch case

Used to make large nested if structures Used to make large nested if structures more readablemore readable

Syntax:Syntax:switch(VarName)switch(VarName){{

case FirstCase:case FirstCase:break;break;

case NextCase:case NextCase:break;break;

default:default:}}

Page 12: Siebel Scripting 3

Decisions: switch caseDecisions: switch case

Example:Example:switch(iScore)switch(iScore){{

case 60:case 60:sGrade = “Fail”;sGrade = “Fail”;break;break;

case 100:case 100:sGrade = “Perfect”:sGrade = “Perfect”:break;break;

default:default:sGrade = “Passing”sGrade = “Passing”

}}

Page 13: Siebel Scripting 3

Looping: for LoopLooping: for Loop

Syntax:Syntax:for (start;condition;increment)for (start;condition;increment){{

‘‘Code to execute each iteration of loopCode to execute each iteration of loop}}

Example:Example:for (iCtr = 0;iCtr<10;iCtr++)for (iCtr = 0;iCtr<10;iCtr++){{

sStepNum = “Step Number: “ + Str$(iCtr);sStepNum = “Step Number: “ + Str$(iCtr);}}

Page 14: Siebel Scripting 3

Looping: do LoopLooping: do Loop

Syntax:Syntax: dodo {{

‘‘Code to execute each iteration of the loopCode to execute each iteration of the loop }while (Condition);}while (Condition);

Example:Example: iCtr = 0;iCtr = 0; dodo {{

iCtr = iCtr + 1;iCtr = iCtr + 1;sStepNum = “Step Number: “ & Str$(iCtr);sStepNum = “Step Number: “ & Str$(iCtr);

} while (iCtr < 10);} while (iCtr < 10);

Page 15: Siebel Scripting 3

Looping: while LoopLooping: while Loop

While loop has same syntax as do loop, While loop has same syntax as do loop, but Condition is at the top, instead of but Condition is at the top, instead of the bottomthe bottom

In a do loop, the loop will always In a do loop, the loop will always execute at least onceexecute at least once

In a while loop, the loop will not execute In a while loop, the loop will not execute even once if the condition is not true even once if the condition is not true the first time through the loopthe first time through the loop

Page 16: Siebel Scripting 3

FunctionsFunctions

All functions in eScript are referred to All functions in eScript are referred to as functions whether or not they as functions whether or not they return a valuereturn a value

Simple types are passed by value Simple types are passed by value unless you place an ampersand in unless you place an ampersand in front of the variable name (&)front of the variable name (&)

Objects and arrays are always Objects and arrays are always passed by referencepassed by reference

Page 17: Siebel Scripting 3

FunctionsFunctions

Syntax:Syntax:function FuncName (Var1, Var2)function FuncName (Var1, Var2){{

‘‘Code to execute inside functionCode to execute inside function‘‘Use return (Value); to return a valueUse return (Value); to return a value

}}

Page 18: Siebel Scripting 3

FunctionsFunctions

Example:Example:function GetName ()function GetName (){{

var sName = “”;var sName = “”;sName = GetProfileAttr(“SPN_CA_NAME”);sName = GetProfileAttr(“SPN_CA_NAME”);return (sName);return (sName);

}}

Page 19: Siebel Scripting 3

Calling FunctionsCalling Functions

Syntax:Syntax:Var = FuncName(Value)Var = FuncName(Value)FuncName (FuncName(Value))FuncName (FuncName(Value))

Example:Example:var sName = GetName();var sName = GetName();

Example 2:Example 2:FindValue(GetName());FindValue(GetName());‘‘FindValue is some other function that FindValue is some other function that

takes a string as a parametertakes a string as a parameter

Page 20: Siebel Scripting 3

ArraysArrays

Declaring:Declaring:var ArrayName = new var ArrayName = new

Array(NumElements);Array(NumElements);Useful methods for arraysUseful methods for arrays

getArrayLength(), length property: Returns getArrayLength(), length property: Returns the number of elements in an arraythe number of elements in an array

reverse(), sort()reverse(), sort()setArrayLength(num): dynamically resizes setArrayLength(num): dynamically resizes

the arraythe arrayjoin() : creates a string from array join() : creates a string from array

elementselements

Page 21: Siebel Scripting 3

Some Important eScript Some Important eScript MethodsMethods

new Date (in place of Now)new Date (in place of Now)The Clib ObjectThe Clib ObjectString Manipulation in eScriptString Manipulation in eScriptFile Handling in eScriptFile Handling in eScript

Page 22: Siebel Scripting 3

new Datenew Date

Returns Current Time and Date on Returns Current Time and Date on machine that the script is running onmachine that the script is running onRunning Web Client or Wireless Web Running Web Client or Wireless Web

Client, that is the Siebel Server that the Client, that is the Siebel Server that the AOM is running onAOM is running on

Running Mobile Web Client or Dedicated Running Mobile Web Client or Dedicated Web Client, that is the machine that Web Client, that is the machine that Siebel.exe is running on- the client’s Siebel.exe is running on- the client’s machinemachine

Syntax: var MyDate = new Date;Syntax: var MyDate = new Date;

Page 23: Siebel Scripting 3

The Clib ObjectThe Clib Object

Has many uses, including file Has many uses, including file handling, string manipulation, handling, string manipulation, character typingcharacter typing

Character Typing functions:Character Typing functions:isalpha()isalpha()isalnum()isalnum()isdigit()isdigit()toascii()toascii()Many othersMany others

Page 24: Siebel Scripting 3

String ManipulationString Manipulation

More than one way, but the easiest More than one way, but the easiest is:is:

First, put the string into an array of First, put the string into an array of one character long strings (no char one character long strings (no char data type)data type)Use Clib.substring() Use Clib.substring()

Next, use for loop to iterate through Next, use for loop to iterate through array, and parse the string as you array, and parse the string as you would in C++would in C++

Page 25: Siebel Scripting 3

File HandlingFile Handling

Clib.fopen()Clib.fopen()File PointersFile PointersClib.rewind()Clib.rewind()Clib.fgets()Clib.fgets()Clib.fprintf()Clib.fprintf()Clib.close()Clib.close()

Page 26: Siebel Scripting 3

Opening FilesOpening Files

Syntax:Syntax:fpname = Clib.fopen(filename, “r”|”w”);fpname = Clib.fopen(filename, “r”|”w”);

Examples:Examples:var fp;var fp;var filename = “C:\MyFile.txt”;var filename = “C:\MyFile.txt”;fp = Clib.fopen(filename, “r”);fp = Clib.fopen(filename, “r”);

Page 27: Siebel Scripting 3

Clib.rewind() MethodClib.rewind() Method

Sets the File pointer position to the Sets the File pointer position to the beginning of the filebeginning of the file

Should always be done on opening a Should always be done on opening a filefile

Page 28: Siebel Scripting 3

Reading From FilesReading From Files

Use fgets()Use fgets()Syntax:Syntax:

Clib.fgets(fpname);Clib.fgets(fpname);Example:Example:

fp = Clib.fopen(filename, "r");fp = Clib.fopen(filename, "r");Clib.rewind(fp);Clib.rewind(fp);

while (!Clib.feof(fp))while (!Clib.feof(fp)){{

sXML = sXML + Clib.fgets(fp);sXML = sXML + Clib.fgets(fp);}}

Clib.fclose(fp);Clib.fclose(fp);

Page 29: Siebel Scripting 3

Clib.feof() MethodClib.feof() Method

Takes a file pointer as argumentTakes a file pointer as argumentReturns true if file pointer is at the Returns true if file pointer is at the

end of the fileend of the file

Page 30: Siebel Scripting 3

Clib.fprintf() MethodClib.fprintf() Method

Writes Data to an open fileWrites Data to an open fileSyntax:Syntax:

Clib.fprintf(filepointername, Value);Clib.fprintf(filepointername, Value);Example:Example:

fp = Clib.fopen(filename, "w");fp = Clib.fopen(filename, "w");Clib.rewind(fp);Clib.rewind(fp);Clib.fprintf(fp, “Write This To the file”);Clib.fprintf(fp, “Write This To the file”);Clib.fclose(fp);Clib.fclose(fp);

Page 31: Siebel Scripting 3

Clib.fclose() MethodClib.fclose() Method

Always Make sure to close your files Always Make sure to close your files after use!after use!

Syntax: Syntax: Clib.fclose(filepointername);Clib.fclose(filepointername);

Page 32: Siebel Scripting 3

Siebel Specific ObjectsSiebel Specific Objects

BusCompBusCompBusObjectBusObjectTheApplicationTheApplicationPropertySetPropertySetServiceServiceObjectObjectParentheses!Parentheses!

Page 33: Siebel Scripting 3

Error Handling With eScriptError Handling With eScript

MUCH more robust than Siebel VBMUCH more robust than Siebel VBUses try-catch-throw system similar Uses try-catch-throw system similar

to Cto CRemember that the Siebel system Remember that the Siebel system

itself is already set up to handle itself is already set up to handle many errors, so most don’t even many errors, so most don’t even need to be handled by youneed to be handled by you

Page 34: Siebel Scripting 3

Error Handling SyntaxError Handling Syntax

try {}try {} Place try block around code that might errorPlace try block around code that might error

catch(e) {}catch(e) {} Catch block goes after. If code in try block errors, Catch block goes after. If code in try block errors,

will throw error e to catch block. Handle errors will throw error e to catch block. Handle errors herehere

throw(e);throw(e); Alternatively, just use error (for example, to write Alternatively, just use error (for example, to write

a log file), then re-throw it for System to handle. a log file), then re-throw it for System to handle. Place inside catch blockPlace inside catch block

finally {}finally {} Used to place code that should be executed even Used to place code that should be executed even

if the catch block halts executionif the catch block halts execution