Siebel cScript




Introduction

eScript is Siebel’s de-facto scripting language, but in an alternate universe, Siebel could have called its scripting language cScript, in reference to its C heritage. eScript is based on the ECMA Script standard (from which JavaScript is also based upon), and shares the same C family style syntax, but it also has uncanny similarities to C that are unparalleled by other ECMA Script derivatives.

Here are 5 good reasons, why Siebel could have called its scripting language cScript instead of eScript.

1. Compiled Code

eScript code is compiled, and runs outside of a browser, just like C.

2. Pre-processors

Pre-processor directives tell the compiler to perform specific actions before the code is actually compiled.

A typical C program is constructed like so:

#include <stdio.h>
int main(void)
{
    printf(“hi”);
}

#include is an example of a pre-processor directive.This tells compiler to import the standard IO library and make it available to the program.

Veteran Siebel programmers will also recognise that the same syntax is used in eScript for EAI purposes.

#include "eaisiebel.js"

This pre-processor isn't explicitly documented under the main eScript reference, but it is hidden away under the following section.

Siebel eScript Language Reference > Compilation Error Messages > Preprocessing Error Messages
http://docs.oracle.com/cd/B40099_02/books/eScript/eScript_Troubleshooting6.html#wp1012712

It is also mentioned in

Business Processes and Rules: Siebel Enterprise Application Integration > Data Mapping Using Scripts > EAI Data Transformation
http://docs.oracle.com/cd/B40099_02/books/EAI4/EAI4_DataMapUSScripts3.html

A small caveat. The #include directive can be written in the following two styles in C.

#include <eaisiebel.js>
#include "eaisiebel.js"

The <> brackets tell the compiler to look in a predetermined directory, while the “”(two double quotes) tell the compiler to look in the current directory as the c program, however in Siebel, when the “” is used, Siebel will look in Tools\Scripts\ for the include file. (Siebel v8+)

3. Libraries

In the above code sample under Pre-Processors, we saw the usage of a function called “printf”. printf outputs a formatted to the standard console. This isn’t part of the core C language, but was made available via the include pre-processor directive, which imports this command into the program from standard libraries.

Standard C libraries from stdio.h, stdlib.h, are also available in Siebel, but there’s no need to include them, Siebel has conveniently wrapped these libraries in Siebel and exposed them through the Clib global object.

eg.
Clib.rsprintf – returns a formatted string to the supplied variable.
Clib.fscanf – read data from file stream

The complete Clib object reference can be found here
http://docs.oracle.com/cd/B40099_02/books/eScript/eScript_JSReference109.html

4. Reference Operators

The following example shows how reference operators are used in a C program.

#include &lt;stdio.h>
 
void sub(int* main_int)
{
    *main_int=10;
    printf("Address sub:\t %d\n",&*main_int);
}
 
int main()
{
    int myInt=5;
    printf("Address main:\t %d\n",&myInt);
    printf("Before Value:\t %d\n",myInt);
    sub(&myInt);
    printf("After Value:\t %d\n",myInt);
}
//Results
/*
Address main:    2293340
Before Value:    5
Address sub:     2293340
After Value:     10
*/


In the above code, an int is given the value 5, its address reference in memory is provided to a sub function using a reference operator

sub(&myInt);

The sub function takes this reference, goes to its address in memory, and modifies the original value.

We can the same functionality in eScript with the following code

function sub(&main_int)
{
    main_int=10;
}
 
function main(Inputs, Outputs){
    var myInt=5;
    Outputs.SetProperty("Before Value",myInt);
    sub(myInt);
    Outputs.SetProperty("After Value",myInt);
}
//Results
/*
Before Value:    5
After Value:     10
*/

Note: The reference operator in this case is declared in the sub function input argument. This tells Siebel to treat &main_int as a pointer to the original value, instead of a copy.

5. Memory pointers

Like all relatives, eScript and C share common ancesters. In this case, the commonality is in the sharing of memory pointers.

The following example shows how an invoked C program can modify data inside eScript. This example is sourced from the bookshelf document on SElib
http://docs.oracle.com/cd/B31104_02/books/eScript/eScript_JSReference253.html

In summary, a couple of buffer objects are created.

    var P_CHURN_SCORE = Buffer(8);
    var R_CHURN_SCORE = Buffer(8);


SElib is used to call a DLL, passing in the reference to the buffer

SElib.dynamicLink("jddll.dll", "score", CDECL,
…
    P_CHURN_SCORE,
    R_CHURN_SCORE,
);


The following C snippet, de-references the pointers, and modifies the data at the memory address that was allocated in the above eScript code.

#include 
_declspec(dllexport) int __cdecl
score (…
    double *P_CHURN_SCORE,
    double *R_CHURN_SCORE
{
    *P_CHURN_SCORE = AGE + AVGCHECKBALANCE + AVGSAVINGSBALANCE;
    *R_CHURN_SCORE = CHURN_SCORE + CONTACT_LENGTH + HOMEOWNER;
    return(1);
}


Clib vs eScript

There is an obvious overlap between CLib and eScript functions, which causes some confusion on which is better to use. The recommendation from Siebel, is to use the eScript equivalent over Clib.

The CLib library is useful for OS level operations, and those scenarios where you need to operate at the memory level, but such usage is usually confined to edge cases, otherwise eScript provides a safer and more familiar playground for Siebel professionals.

Conclusion

Siebel designed eScript as a hybrid of ECMA Script and C, providing customers with the (not so well documented) ability to extend eScript beyond its natural abilities. Although everyday configurators may never need to touch the Clib libraries, use pre-process instructions, utilize reference operators or even call custom DLL's, but understanding these advanced features, and recognizing the C heritage provides insights for experienced developers, to maximize, and extend the product beyond its out of the box capabilities.

Finally, as for the great idea of renaming eScript, unfortunately the cScript moniker is already taken (most notably by cscript.exe from MS), but you could also argue the same for 'eScript', which is claimed by these other software companies.

eScript - Eclipse scripting language
http://wiki.eclipse.org/FAQ_What_is_eScript%3F

EScript - C++ Scripting language
http://escript.berlios.de/pmwiki/pmwiki.php

Escript – Python programming tool
https://launchpad.net/escript-finley/

escript – Erlang scripting language
http://www.erlang.org/doc/man/escript.html

eScript.api - This is the name of an Adobe plugin
http://www.processlibrary.com/en/directory/files/escript/403646/

As a consolation, we could designate eScripters who primarily use Clib, cScripters. I think this might catch on =)