7044162 siebel scripting 3

Upload: suresh4ever

Post on 06-Apr-2018

247 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/3/2019 7044162 Siebel Scripting 3

    1/34

    Siebel Scripting, Part TwoSiebel Scripting, Part Two

    eScript SyntaxeScript Syntax

  • 8/3/2019 7044162 Siebel Scripting 3

    2/34

    IntroductionIntroduction

    Data TypesData Types

    Declaring VariablesDeclaring Variables

    OperatorsOperators DecisionsDecisions

    LoopingLooping

    FunctionsFunctionsArrays in eScriptArrays in eScript

    Some Important eScript MethodsSome Important eScript Methods

    Using Siebel ObjectsUsing Siebel Objects

  • 8/3/2019 7044162 Siebel Scripting 3

    3/34

    Comments in eScriptComments in eScript

    Use two forward slashes // at the front ofUse two forward slashes // at the front ofa line to make a single line commenta line to make a single line comment

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

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

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

    stretches overstretches over

    multiple lines */multiple lines */

  • 8/3/2019 7044162 Siebel Scripting 3

    4/34

    Data TypesData Types

    There ARE no data types in eScriptThere ARE no data types in eScript

    eScript is aeScript is a loose typedloose typed languagelanguage

    Variables can change type dynamicallyVariables can change type dynamically eScript is Case SensitiveeScript is Case Sensitive

    var MyString and var mystring are twovar MyString and var mystring are two

    DIFFERENT variables!DIFFERENT variables!

  • 8/3/2019 7044162 Siebel Scripting 3

    5/34

    OperatorsOperators

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

    C

    onditional OperatorsC

    onditional Operators==, !=, , ===, !=, , =

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

    AssignmentAssignment==

    TernaryTernary

    Condition ? Do If True : Do If FalseCondition ? Do If True : Do If False

  • 8/3/2019 7044162 Siebel Scripting 3

    6/34

    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 sameCan declare more than one variable of the same

    type in one line: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;

  • 8/3/2019 7044162 Siebel Scripting 3

    7/34

    Decisions: ifDecisions: if

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

    {{

    Code to be executed ifCondition is TrueCode to be executed ifCondition is True }}

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

    {{ sGrade = Fail;sGrade = Fail;

    }}

    Simple Decision Making ConstructSimple Decision Making Construct

  • 8/3/2019 7044162 Siebel Scripting 3

    8/34

    Decisions: elseDecisions: else

    Syntax:Syntax:

    if (Condition)if (Condition)

    {{

    Code to Execute ifCondition is TrueCode to Execute ifCondition is True

    }}

    elseelse

    {{Code to Execute ifCondition is FalseCode to Execute ifCondition is False

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    9/34

    Decisions: elseDecisions: else

    Example:Example:

    if (iScore < 60)if (iScore < 60)

    {{sGrade = Fail;sGrade = Fail;

    }}

    elseelse

    {{

    sGrade = Passing;sGrade = Passing;

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    10/34

    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;

    };};

  • 8/3/2019 7044162 Siebel Scripting 3

    11/34

    Decisions: switch caseDecisions: switch case

    Used to make large nested if structures moreUsed to make large nested if structures morereadablereadable

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

    {{

    case FirstCase:case FirstCase: break;break;

    case NextCase:case NextCase: break;break;

    default:default:

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    12/34

    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 = PassingsGrade = Passing

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    13/34

    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

  • 8/3/2019 7044162 Siebel Scripting 3

    14/34

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

  • 8/3/2019 7044162 Siebel Scripting 3

    15/34

    Looping: while LoopLooping: while Loop

    While loop has same syntax as do loop, butWhile loop has same syntax as do loop, butCondition is at the top, instead of the bottomCondition is at the top, instead of the bottom

    In a do loop, the loop will always execute atIn a do loop, the loop will always execute atleast onceleast once

    In a while loop, the loop will not executeIn a while loop, the loop will not executeeven once if the condition is not true the firsteven once if the condition is not true the firsttime through the looptime through the loop

  • 8/3/2019 7044162 Siebel Scripting 3

    16/34

    FunctionsFunctions

    All functions in eScript are referred to asAll functions in eScript are referred to asfunctions whether or not they return afunctions whether or not they return a

    valuevalue Simple types are passed by value unlessSimple types are passed by value unless

    you place an ampersand in front of theyou place an ampersand in front of thevariable name (&)variable name (&)

    Objects and arrays are always passed byObjects and arrays are always passed byreferencereference

  • 8/3/2019 7044162 Siebel Scripting 3

    17/34

    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

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    18/34

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

    }}

  • 8/3/2019 7044162 Siebel Scripting 3

    19/34

    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 takes aFindValue is some other function that takes astring as a parameterstring as a parameter

  • 8/3/2019 7044162 Siebel Scripting 3

    20/34

    ArraysArrays

    Declaring:Declaring:

    var ArrayName = new Array(NumElements);var ArrayName = new Array(NumElements);

    Useful methods for arraysUseful methods for arrays getArrayLength(), length property: Returns thegetArrayLength(), length property: Returns the

    number of elements in an arraynumber of elements in an array

    reverse(), sort()reverse(), sort()

    setArrayLength(num): dynamically resizes thesetArrayLength(num): dynamically resizes thearrayarray

    join() : creates a string from array elementsjoin() : creates a string from array elements

  • 8/3/2019 7044162 Siebel Scripting 3

    21/34

    Some Important eScript MethodsSome Important eScript Methods

    new Date (in place of Now)new Date (in place of Now)

    The Clib ObjectThe Clib Object

    String Manipulation in eScriptString Manipulation in eScript File Handling in eScriptFile Handling in eScript

  • 8/3/2019 7044162 Siebel Scripting 3

    22/34

    new Datenew Date

    Returns Current Time and Date onReturns Current Time and Date onmachine that the script is running onmachine that the script is running on

    Running WebC

    lient or Wireless WebC

    lient,Running WebC

    lient or Wireless WebC

    lient,that is the Siebel Server that the AOM isthat is the Siebel Server that the AOM isrunning onrunning on

    Running Mobile Web Client or Dedicated WebRunning Mobile Web Client or Dedicated Web

    Client, that is the machine that Siebel.exe isClient, that is the machine that Siebel.exe isrunning onrunning on-- the clients machinethe clients machine

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

  • 8/3/2019 7044162 Siebel Scripting 3

    23/34

    The Clib ObjectThe Clib Object

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

    Character Typing functions:

    Character Typing functions: isalpha()isalpha()

    isalnum()isalnum()

    isdigit()isdigit()

    toascii()toascii()

    Many othersMany others

  • 8/3/2019 7044162 Siebel Scripting 3

    24/34

    String ManipulationString Manipulation

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

    First, put the string into an array of oneFirst, put the string into an array of one

    character long strings (no char data type)character long strings (no char data type) Use Clib.substring()Use Clib.substring()

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

  • 8/3/2019 7044162 Siebel Scripting 3

    25/34

    File HandlingFile Handling

    Clib.fopen()Clib.fopen()

    File PointersFile Pointers

    Clib.rewind()Clib.rewind() Clib.fgets()Clib.fgets()

    Clib.fprintf()Clib.fprintf()

    Clib.close()Clib.close()

  • 8/3/2019 7044162 Siebel Scripting 3

    26/34

    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:var filename = C:\\MyFile.txt;MyFile.txt;

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

  • 8/3/2019 7044162 Siebel Scripting 3

    27/34

    Clib.rewind() MethodClib.rewind() Method

    Sets the File pointer position to theSets the File pointer position to thebeginning of the filebeginning of the file

    Should always be done on opening a fileShould always be done on opening a file

  • 8/3/2019 7044162 Siebel Scripting 3

    28/34

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

  • 8/3/2019 7044162 Siebel Scripting 3

    29/34

    Clib.feof() MethodClib.feof() Method

    Takes a file pointer as argumentTakes a file pointer as argument

    Returns true if file pointer is at the end ofReturns true if file pointer is at the end of

    the filethe file

  • 8/3/2019 7044162 Siebel Scripting 3

    30/34

    Clib.fprintf() MethodClib.fprintf() Method

    Writes Data to an open fileWrites Data to an open file

    Syntax:Syntax:

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

    fp = Clib.fopen(filename, "w");fp = Clib.fopen(filename, "w");

    C

    lib.rewind(fp);C

    lib.rewind(fp); Clib.fprintf(fp, Write This To the file);Clib.fprintf(fp, Write This To the file);

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

  • 8/3/2019 7044162 Siebel Scripting 3

    31/34

    Clib.fclose() MethodClib.fclose() Method

    Always Make sure to close your files afterAlways Make sure to close your files afteruse!use!

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

  • 8/3/2019 7044162 Siebel Scripting 3

    32/34

    Siebel Specific ObjectsSiebel Specific Objects

    BusCompBusComp

    BusObjectBusObject

    TheApplicationTheApplication PropertySetPropertySet

    ServiceService

    ObjectObject Parentheses!Parentheses!

  • 8/3/2019 7044162 Siebel Scripting 3

    33/34

    Error Handling With eScriptError Handling With eScript

    MUCH more robust than Siebel VBMUCH more robust than Siebel VB

    Uses tryUses try--catchcatch--throw system similar to Cthrow system similar to C

    Remember that the Siebel system itself isRemember that the Siebel system itself isalready set up to handle many errors, soalready set up to handle many errors, somost dont even need to be handled bymost dont even need to be handled byyouyou

  • 8/3/2019 7044162 Siebel Scripting 3

    34/34

    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, willCatch block goes after. If code in try block errors, willthrow error e to catch block. Handle errors herethrow error e to catch block. Handle errors here

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

    file), then refile), then re--throw it for System to handle. Place insidethrow it for System to handle. Place insidecatch blockcatch block

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

    catch block halts executioncatch block halts execution