Command Reference CIB jsMerge

Coming from RTF: Comparison of Functions

For users that come from an MS Word and RTF environment it can be helpful to see how the already known field instructions in RTF are mapped to the ODT environment.


Mapping RTF Field Instructions to Script Logic

This section shows how RTF field instructions and their logic can be realized with the new scripting logic. The following table provides a list of all RTF fields, how they are processed by CIB merge and the corresponding realization in JavaScript scripting logic:

Field Instruction (en / de)

Description (from CIB merge technical reference)

ODT or script logic realization (JavaScript)

COMPARE / VERGLEICH

Compares 2 values and returns the numeric value 1 if the result is true, 0 (null) if the result is false.

JavaScript: Boolean comparison

Example: (a==b)

DATE / AKTUALDAT

Inserts the current date.

Please see:
formatDate(formatString, date).

IF / WENN

Compares arguments while taking into account certain conditions. Can be extended to a loop instruction (SOLANGE)

JavaScript: IF command

Example: if(a==b){ ... }else{ ...}

 

while(a==b) { … }
(for
SOLANGE)

INCLUDETEXT / EINFÜGENTEXT

Inserts a text from a file.

Please see:
include(name,
{includeAttributes})

Example:
include(„mydoc.odt“)

MERGEFIELD / SERIENDRUCKFELD

Creates a placeholder with a name, which is later replaced by variable content.

Please see:
fref(name,
{formfieldAttributes}) or
text(ref(name))

Example: text(ref(“institute.EL_KIN_BEZ”))

MERGEREC / DATENSATZ

Inserts the number of the current merge record.

Please see:
mergeRec()

Example:
mergeRec()

MERGEREC ?

Returns Boolean "1" if there still is a merge record. By default it is set to "0".

Please see:
hasRec()

Example:
hasRec()

MERGEREC „tablealias“

Adds the number of the current record of a table.

Please see:
mergeRec(tablealias)

Example:
mergeRec("Persons")

MERGEREC "?tablealias"

Returns 0 if no further records are in this table.

Please see:
hasRec(tablealias)

Example: while(hasRec(„Persona“)) …

NEXT / NÄCHSTER

Goes to the next record or node in the data supply.

Please see:
nextRec()

Example:
 
nextRec()

NEXT -

Resets all control files to record "zero". The variable contents are deleted. The values of the first record are first read with {NEXT}

Please see:
resetRec()

Example:
resetRec()

NEXT aliasname

Proceeds to the next record or node in the data list described by the alias name

Please see:
nextRec(tablealias)

Example:
nextRec(„Persons“)

NEXT –aliasname

NEXT aliasname

These two commands reset the data list to the 1st record.

Please see:
resetRec(tablealias)

Example:
resetRec(„Persons“)

NEXTIF / NWENN

Proceeds to the next record or node in the data supply if a certain condition is met.

Valid with merging and iterating lists.

JavaScript:
if(<condition>) nextRec()

or

if(<condition>)
    nextRec(tablealias)

QUOTE / ANGEBEN

Inserts a text to the document.

Please see:
text(text)

Example:
text(„Hello world“)

REF / REF

Creates a placeholder with a name, that is later replaced by variable content.

Please see:
fref(name,
{formfieldAttributes}) or
text(ref(name))

Example: text(ref(“institute.EL_KIN_BEZ”))

REF "?variable"

Returns "0" if the variable does not exist, else returns "1".

Please see:
existsRef(variableName)

Example:
 
existsRef(„<variable>“)

SET / BESTIMMEN

Assigns a new text to a text mark.

Please see:
setData(variableName, value)

Example:
setData(„myVar“, 1)

SKIPIF / ÜBERSPRINGEN

Skips a record or node in the data supply according to a condition and doesn't create an output document in the merge run for this record.

Only valid with merging. Not applicable with lists.

JavaScript:
if(<condition>) skip()

TIME / ZEIT

Inserts the current time.

TIME is always interpreted by CIB merge. In some cases it is desirable that CIB format does the replacement. Then the \* keep switch is used.

Please see:
formatDate(formatString, date).

= Ausdruck / Expression

Calculates the result of a expression (= formulae)

JavaScript formulae

Examples:
(3-1) or
(5*10) or
(10%2) or (Number(ref(“myNumber”)) + 10)

Attention:
in JavaScript the "+" operator is used per default for string concatenation. The operators have to be specified with Number() to force an addition.

 

Examples follow for how RTF expressions can be realized in script fields.

MS Office field instructions

Script logic (Examples in JavaScript)

Simple REF:

{ REF “institute.EL_KIN_BEZ” }

{# text(ref(“myVariable)) }

Simple SET:

{ SET myVar “Hello” }

{# setData(“myVar”, “Hello”) }

REF with Date format switch:

{ REF myDate \@ “tt.mm.jjjj” }

{# text(formatDate(“tt.mm.jjjj”, ref(“myDate”))) }

Simlple "IF-then" construct:

{ IF { REF “myVariable” } = “” “My variable is empty” }

{# if(ref(“myVariable)==””) {My variable is empty}}

The function would terminate here with an error if "myVariable" could not be resolved.

or

{# if(isEmptyRef(“myVariable)) {My variable is empty}}

The function would terminate with an error if "myVariable" could not be resolved.

Check if variable is empty:

{ IF { REF “myVariable” } != “” “{ REF myVariable”}}

{# if(!isEmptyRef(“myVariable”)) text(ref(“myVariable”)}

Simple "IF-then-else" construct:

{ IF <condition> “then-part” “else-part” }

{# if(<condition>) {‘then-part} else {‘else-part} }

Check if variable exists (and define it if it doesn't):

{ IF myVar = “myVar” {SET myVar “Hello” }}

or:

{ IF { REF ?myVarXXX } = 0 { SET myVarXXX “Hello” }}

Several of these constructs can be dealt with in a script field:

{#if(!existsRef(„myVar“))
  set(„myVar“, „Hello“);
if(!existsRef(„myVarXXX“))
  set(„myVarXXX“, „Hello“);
}

Simple calculation:

{ SET myVar { = 1 +2 + 3 }}

{# set(“myVar”, 1 + 2 + 3) }

Calculation with variable:

{ SET myVar { = { REF myNumber } + 2 + 3 }}

{# set(“myVar”, Number(ref(“myNumber”)) + 2 + 3) }

In JavaScript numeric variables have to be specified with "Number()" to differentiate from string variables. Default for "+" is a string concatenation.

String concatenation:

{ REF “var{ REF myNumber }}

{# text(ref(“var” + ref(myNumber))) }

SET-IF:

{ SET “myVar” { IF <condition> “She” “He” }}

{# setData(“myVar”, (<condition>)? “She” : “He”) }

or

{# if(<condition>) setData(“myVar”, “She”);
   else setData(“myVar, “He”);
}

Compare:

{ set “valid” { ={ COMPARE { REF a } = 1} && { COMPARE { REF b } = 2} && { COMPARE { REF c } = 3}}}

{# setData(“valid”, (ref(“a”)==1) && (ref(“b”)==2) && (ref(“c”)==3)) }

SOLANGE-loop:

{ if <condition> “…content…
{ next … }” \* SOLANGE }

{# while(<condition>) {…content…
{# nextRec(…) }}}

Next –aliasname:

{ next –aliasname }

{# resetRec(“aliasname”) }

Simple INCLUDETEXT:

{ INCLUDETEXT “template.rtf” }

{# include(“template.odt”) }