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: |
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) { … } |
INCLUDETEXT / EINFÜGENTEXT |
Inserts a text from a file. |
Please
see: Example: |
MERGEFIELD / SERIENDRUCKFELD |
Creates a placeholder with a name, which is later replaced by variable content. |
Please
see: Example: text(ref(“institute.EL_KIN_BEZ”)) |
MERGEREC / DATENSATZ |
Inserts the number of the current merge record. |
Please
see: Example: |
MERGEREC ? |
Returns Boolean "1" if there still is a merge record. By default it is set to "0". |
Please
see: Example: |
MERGEREC „tablealias“ |
Adds the number of the current record of a table. |
Please
see: Example: |
MERGEREC "?tablealias" |
Returns 0 if no further records are in this table. |
Please
see: Example: while(hasRec(„Persona“)) … |
NEXT / NÄCHSTER |
Goes to the next record or node in the data supply. |
Please
see: Example: |
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: Example: |
NEXT aliasname |
Proceeds to the next record or node in the data list described by the alias name |
Please
see: Example: |
NEXT –aliasname NEXT aliasname |
These two commands reset the data list to the 1st record. |
Please
see: Example: |
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:
or if(<condition>) |
QUOTE / ANGEBEN |
Inserts a text to the document. |
Please
see: Example: |
REF / REF |
Creates a placeholder with a name, that is later replaced by variable content. |
Please
see: Example: text(ref(“institute.EL_KIN_BEZ”)) |
REF "?variable" |
Returns "0" if the variable does not exist, else returns "1". |
Please
see: Example: |
SET / BESTIMMEN |
Assigns a new text to a text mark. |
Please
see: Example: |
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: |
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: |
= Ausdruck / Expression |
Calculates the result of a expression (= formulae) |
JavaScript formulae Examples: Attention: |
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“)) |
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”); |
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… |
{# while(<condition>) {…content… |
Next –aliasname: { next –aliasname } |
{# resetRec(“aliasname”) } |
Simple INCLUDETEXT: { INCLUDETEXT “template.rtf” } |
{# include(“template.odt”) } |