Show TOC Start of Content Area

Background documentation Script Language  Locate the document in its SAP Library structure

Use

You can use the scripting language to embed script elements in the content of e-mail templates. As with the UNIX script languages, a grave accent (`) character is used to begin and close the script elements.

The scripting language used in the GP e-mail templates supports checking conditions, basic mathematical functions, using built-in parameters, and accessing context parameters. For more information about how to access context parameters, built-in parameters, and the built-in process roles, see Replacements.

The basic syntax of the scripting language is described in this documentation.

Basics of the Script Language

General Language Elements

Syntax

Description

eval(expression)

Evaluates an expression

exists(expression)

Checks the existence of a context variable

write(expression)

Writes its argument into the content of the e-mail

writeln(expression)

Writes its argument into the content of the e-mail and appends a new line to it

fcount(expression)

Reserved, but not used by GP

Example

` writeln( " This text will be displayed in the e-mail " )`

Flow Control Elements

Syntax

Description

if (expression) {…} else {…}

 

 

 

 

 

 

 

C-like if command (note that the else branch is mandatory, not optional)

Example

`i = 1;

if( i == 1 ) { `i is 1

` } else { `i is not 1

` };

switch (expression)  {
case expression1: …
  break;
case expressionN: …
default:
}

 

 

 

 

 

 

 

 

 

 

C-like switch command

Example

`i = 1;

while( i < 4 ) {

  switch( i ) {

    case 1: `with break

` break;

    case 2: `no break -> default

`

    default: `the default`

  }

  i = i + 1;

} `

while (expression) {…}

 

 

 

 

 

C-like while command
Example

`i = 1;

while( i < 4 ) {writeln(i); i = i + 1; }`

loop

Reserved, but not used by GP

loopidx

Reserved, but not used by GP

stop

Stops processing of the file (HTML template file or plain text file containing the script)

String Handling Functions

Syntax

Description

codejs(string)

Not used by GP

codeurl(string)

Encodes a string into a URL-encoded string

substr

Returns a substring of the string

len(string)

Returns the length of the string

Example

`writeln(  " name@company-emailaddress.com "  );

string2 = codeurl( " name@company-emailaddress.com " );

write( string2 )`

Mathematical Functions

Syntax

Description

not(number)

Negation

add(number, number)

Addition

sub(number, number)

Subtraction

div(number, number)

Division

mod(number, number)

Mod

mul(number, number)

Multiplication

Example

`writeln( mod( 3, 2 ) );`

Comparison

Syntax

Description

==

Equal to

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

Example

`i = 1; i2 = 2;

if( i <= i2 ) { ` i < i2

` } else { `i2 > i

` }

i = 2; i2 = 1;

if( i <= i2 ) { ` i < i2

` } else { `i2 > i

` }

i = 2; i2 = 2;

if( i <= i2 ) { ` i <= i2

` } else { `i2 > i

` }

 

End of Content Area