Article import - Prefix Postfix C-ENTRON Script (StringInterpreter)
1. General information
With the help of C-ENTRON Script, you can control which data is entered into the database and how, and you can create special prefixes and suffixes.
Example: A distributor provides information in the Description field, and you want to
enter the content in the C-ENTRON Text field. However, if the designation
is empty, you want "No description" to be entered into the database.
This can be achieved with the following C-ENTRON script in the prefix:
@@ "No designation" [Null] @@
2. Syntax
2.1 Script definition
A script is introduced with @@ and ends with @@. Text before a script is returned, text within a script is not returned unless it is enclosed in quotation marks and the corresponding parameters apply. A script can span multiple lines.
Example:
This text is returned. @@ "This one too!" Unfortunately, this text is not. @@
yields
This text is returned. This one too!
Multiple scripts can be created within a prefix or suffix:
Component before Script 1. @@ "Script 1." @@ Text between two scripts. @@ "Script 2." @@
Results
Component before Script 1. Script 1. Text between two scripts. Script
2.2 String formatting
The formatting of strings (i.e., text) can be influenced by specifying line breaks and tabs, as well as the actual value contained in an import field.
2.2.1 Line break
A line break can be inserted into the return value using \n.
Example:
@@ "Text in first line\nText in second line" @@
Results in
Text in first line
Text in second line
2.2.2 Tabulator
A tabulator can be inserted in a similar way to a line break using \t:
@@ "Before tab\tAfter tab" @@
yields
Before tabulator After tabulator
2.2.3 Import field value
Sometimes it is necessary to return the actual value contained in a field of the import file in a prefix or suffix. The syntax \$ is used for this purpose
Example: The field for the item description of a graphics card says "256 MB," but you want to enter "Graphics card has 256 MB RAM" in the text field.
This can be achieved with the following script:
@@ "Graphics card with \$ RAM" @@
The output would be
Graphics card with 256 MB RAM
2.2.4 Special characters
The category of special characters includes double quotation marks ("") and the backslash (\). Since these special characters are within a string (they introduce line breaks, etc. or start/end a string), they must be "escaped." This means that these characters must be preceded by a backslash. For example, to output "\", "\\" must be written in the script.
Example:
@@ "Here you see a backslash: \\. And here comes a double quotation mark: \"" @@
Results
Here you see a backslash: \. And here comes a double quotation mark: „
2.3 parameters
Parameters are used to significantly influence the behavior of a script. By default, a script is only executed if the content of the import field is not NULL or, if it is text, is not empty. The same applies if no script is stored in the prefix/suffix field.
Example: The text "Description:" and then the content of the distributor field should be entered in the C-ENTRON text field Designation be entered, but only if the Designation is not empty.
In this case, the text for the prefix is
Description:
Using a script and parameters, you can now ensure that this text is also written when the contents of the distributor field are empty.
2.3.1 Parameter declaration
Parameters are defined within a script in square brackets and separated from each other by commas.
@@ script [Parameter1, Parameter2] @@
It is possible to split parameters in the script:
@@ script [parameter1] script [parameter2] @@
The parameters always work together. The last example is therefore equivalent to the previous example.
2.3.2 [Always]
The Always parameter causes text to always be written, regardless of whether the content is empty or not. So if you always want to write the text "Designation:", the script would have to look like this:
@@ "Description:" [Always] @@
2.3.3 [NotNull]
The NotNull parameter causes text to be output only if the content of a distributor field is not NULL or, in the case of a text field, is not empty. This parameter is the default setting if no parameters have been specified or if no script has been specified within a prefix or suffix.
Example 1
Example without script
Example 2
@@ "Example with script" @@
Example 3
@@ "Example with script and parameter" [NotNull] @@
All three examples only return text if the distributor field has content.
2.3.4 [Zero]
This parameter can be used to output text if the contents of the distributor field are empty. For example, if you want the text "Description: not available" to be entered in the C-ENTRON field Text when the distributor field is empty and, for example, "Description: Matrox graphics card" when the field is filled, the script would look like this:
Description: @@ "not available" [null] @@
2.3.5 [NoValue]
The NoValue parameter can be used to control whether the actual value is written or not. This parameter is mainly used to make a script clearer.
Example: You want to respond differently depending on whether the distributor field is filled or not, and you don't want to split this between the prefix and suffix, but simply write it in the prefix. The script for this would be as follows:
Description: @@ "$" @@@@ "not available" [null, NoValue] @@
2.3.6 Interaction of parameters
Since parameters can be freely combined with each other and since a prefix or suffix can contain more than one script, which in turn can contain multiple parameters, parameters within a prefix or suffix have a cumulative effect. This means that all parameters set anywhere are set in total.
@@ script1 [Parameter1] @@ @@ script2 [Parameter2] @@ @@ script3 [Parameter3] @@
The example causes all parameters, i.e Parameter1, Parameter2 and Parameter3 are set.
Please note the following regarding the possible parameters: Since the parameters are cumulative, there is a hierarchy in which the parameters take effect. The order is , the parameter NoValue has a global effect, therefore does not influence when something is written.
Example: If you use the parameter Always and set the parameter in another NotNull, then it has a global effect Always and a text is always written:
@@ "Return of Script 1" [Always] @@ "\nReturn of Script 2" [NotNull] @@
The text "Return of Script 1" is therefore always returned.
If you specify more than one parameter that determines the output in a script, the one highest in the hierarchy always takes effect.
In the following example, both the parameter NotNull as well as the parameter Zero used within a script. The return therefore only occurs if the distributor field is filled:
@@ "Return of the script" [NotNull, Null] @@
3. Complex example
In the example, there are the distributor fields "Designation" and "Article group." These should be written in the C-ENTRON field "Text" with the heading "Article description" and indented using tabs for clarity.
Prefix script for the distributor field Description
@@
"Item description\n\tDescription: " [Always]
@@@@
"\$" [NotNull, NoValue]
@@@@
"not available" [null]
@@
Prefix script for the distributor field Article group
@@
"\n\tProduct group: " [Always]
@@@@
"\$" [NotNull, NoValue]
@@@@
"not available" [null]
@@
If the Designation field were set but the Item group field were not, the following would occur Text entered in the C-ENTRON field Text:
Product description:
Name: Matrox Parhelia
Product group: not available