Export template commands – cheat sheet
Before you get started
This article is a cheat sheet for when you're already familiar with export templates. We've also written a detailed guide that explains everything step by step: How do I create a Word file as an export template and which commands can I use for the export?
This article explains where to upload your export template in Vaira afterwards: How do I upload an export template for a workflow?
Overview and quick navigation
- Syntax for standard data exports
- Photos from photo fields
- Sketches from measurements
- Photos from measurements
- Signatures
- Lists
- Checkboxes
- Syntax for conditions
- Syntax for formatting
Syntax for standard data exports
In the following commands, you only need to adjust the values in bold. Don't change anything else – that's the only way Vaira can work with the commands. So please make sure you always use the right type of bracket and copy every quotation mark and every comma.
Tip for anyone who can code: inside the blocks, you can work with regular JavaScript.
Text, number, date, timestamp, user and selection fields
{% raw %}These field types all share the same call:
{# field("taskID/fieldID") #}
Single photos from photo fields
For this field type, you need a basic structure adapted for images, and you also have to specify the width and height.
{# FOR img IN field("taskID/fieldID") #}
{# IMAGE getImage($img, width,height) #}
{# END-FOR img #}
Width and height are specified in cm. You need to specify at least one value; enter undefined for any value you leave out. If you specify only one value, the aspect ratio is preserved; if you specify both width and height, the image may be stretched to fit. Without width and height, the photo is 6 × 6 cm.
Paragraphs and spacing between photos
If you export several photos one below the other, you can add clean spacing inside the loop in your Word template – just like with normal text:
-
Insert empty paragraphs: In your Word template, add a blank line (Enter) between the image command and the END-FOR. It's output with every repetition and creates space between the photos.
-
Use paragraph spacing in Word: In Word, set the paragraph spacing "After" for the line containing the image command (Home › Paragraph). That way, every photo automatically gets the same spacing without blank lines.
-
Example with a blank line in the loop:
{# FOR img IN field("taskID/fieldID") #}
{# IMAGE getImage($img, width, height) #}
← leave a blank line here in Word
{# END-FOR img #}
Multiple photos from photo fields as a gallery
To export photos as a gallery, you first need a command directly before (or above) your table. Add the following code there in your Word template:
{# EXEC
const imagesPerRow = 3;
var images = field("taskID/fieldID");
gallery = [];
while (images.length > 0) {
gallery.push(images.slice(0, imagesPerRow));
images = images.slice(imagesPerRow);
}
#}
Then add the table:
|
{# FOR row IN gallery #} |
|
|
|
{# $row[0].featureId #} {# IMAGE getImage($row[0], 5.5) #} |
{# IF $row.length > 1 #} {# $row[1].featureId #} {# IMAGE getImage($row[1], 5.5) #} {# END-IF #} |
{# IF $row.length > 2 #} {# $row[2].featureId #} {# IMAGE getImage($row[2], 5.5) #} {# END-IF #} |
|
{# END-FOR row #} |
|
|
The code parts {# $row[0].featureId #}, {# $row[1].featureId #} and {# $row[2].featureId #} are optional. If you include them, the photos are exported together with their point number.
Photos from a measurement field
The command is:
{# FOR measurement IN field("taskID/fieldID") #}
{# FOR img IN $measurement.images #}
{# $img.featureId #}
{# IMAGE getImage($img, width,height) #}
{# END-FOR img #}
{# END-FOR measurement #}
Multiple photos from measurement fields as a gallery
To export measurement photos as a gallery, you first need a command directly before (or above) your table. Add the following code there in your Word template:
{# FOR measurement IN field(“taskID/fieldID”) #}
{# EXEC
const imagesPerRow = 3;
var images = $measurement.images;
gallery = [];
while (images.length > 0) {
gallery.push(images.slice(0, imagesPerRow));
images = images.slice(imagesPerRow);
}
#}
{# END-FOR measurement #}
Then add the table. Note: This works reliably if the field contains only one measurement. If there are several measurements, only the photos of the last one appear.
|
{# FOR row IN gallery #} |
|
|
|
{# IMAGE getImage($row[0], 5.5) #} |
{# IF $row.length > 1 #} {# IMAGE getImage($row[1], 5.5) #} {# END-IF #} |
{# IF $row.length > 2 #} {# IMAGE getImage($row[2], 5.5) #} {# END-IF #} |
|
{# END-FOR row #} |
|
|
All sketches from a measurement field
You get all sketches from a measurement field with the following command:
{# FOR measurement IN field("taskID/fieldID") #}
{# IMAGE getImage($measurement.sketch,width,height) #}
{# END-FOR measurement #}
Important: If you specify both width and height, the sketch is drawn in exactly that format. It isn't stretched; instead, the visible area adjusts. If you specify only the width or only the height, that value applies and the other one follows from the aspect ratio. Write undefined for a value you leave out, e.g. ($measurement.sketch,undefined,5). Without width and height, the sketch is 6 × 6 cm.
You can also add one or both of the following commands to the loop. They let you export the display name
{# $measurement.sketch.displayName #}
and the description of each sketch.
{# $measurement.sketch.description #}
If you want to export both, your export command ends up looking like this:
{# FOR measurement IN field("taskID/fieldID") #}
{# IMAGE getImage($measurement.sketch,width,height) #}
{# $measurement.sketch.displayName #}
{# $measurement.sketch.description #}
{# END-FOR measurement #}
You don't need to change anything in the two optional commands.
The look and content of your sketches
You can customize your sketch even further by adding parameters, separated by commas, in curly braces to the sketch call.
{# IMAGE getImage($measurement.sketch,17.5, 19, {fullBackground: true, withMarkers: false, withSymbols: true, withLengthsAndAreas: false, withDimensionLines: true}) #}
withMarkers: trueorwithMarkers: false
- These are the thick, colored measurement points. If you don't specify this, the setting of your export template applies.
withSymbols: trueorwithSymbols: false
- These are the symbols on components and measurement points.
Tip: use either withSymbols: true and withMarkers: false or withSymbols: false and withMarkers: true, but don't set both to true at the same time, so the sketch doesn't get too cluttered.
withDimensionLines: trueorwithDimensionLines: false- These are the dimension lines. If you don't specify this, it follows the value of withMarkers.
withLengthsAndAreas: trueorwithLengthsAndAreas: false- These are the lengths of the individual segments of your measurement and the areas of polygons. If you don't specify this, it follows the value of withDimensionLines.
fullBackground: trueorfullBackground: false- Determines whether the entire background graphic is exported too (with
true), which may make the sketch smaller, or whether the sketch is shown at maximum size and parts of the background graphic are cut off instead (withfalse, which is the default and recommended). With rotation (e.g. rotation: 90), you rotate the sketch clockwise by the specified number of degrees.
- Determines whether the entire background graphic is exported too (with
Exporting a single, specific sketch
Important: This function can lead to unexpected results and should only be used by experienced users. Since it outputs a specific sketch based on the order of the measurements, in most cases it's enough – and advisable – to follow the section All sketches from a measurement field instead and output all sketches.
You get a specific sketch from a measurement field with the following command:
{# IMAGE getImage(field("taskID/fieldID“)[0].sketch,width,height) #}
Width and height are specified in cm. If you specify both, the sketch is drawn in exactly that format; with only one value, the aspect ratio is preserved. Write undefined for a value you leave out.
Optionally, you can also export the display name of the measurement
{# $measurement.sketch.displayName #}
as well as the description of the measurement
{# $measurement.sketch.description #}
Signature from a signature step
This command outputs the drawn signature of a party from a signature step. Replace schrittID with the ID of the step and parteiID with the ID of the party, exactly as they appear in the workflow. The number at the end is the width in centimeters.
{# IMAGE getImage(steps.schrittID.signatures.parteiID, 6) #}
This is how you get the name, place and date of the signature:
{# steps.schrittID.signatures.parteiID.signer #}
{# steps.schrittID.signatures.parteiID.place #}
{# steps.schrittID.signatures.parteiID.date #}
Tip: If the step has several parties, output all of them in a loop: {# FOR p IN steps.schrittID.signers #} … {# END-FOR p #}. Inside the loop, use {# IMAGE getImage($p, 6) #} for the signature, plus $p.displayName (name of the party), $p.signer, $p.place and $p.date. Signatures that haven't been given yet appear as an empty field of the same size, so your document has the same layout before and after signing.
To learn how to collect signatures in Vaira Office and in the Vaira App, see: How can I collect signatures in Vaira Office and in the Vaira App?
Values from lists
To export lists, you first need a command directly before (or above) your table. Add the following code there in your Word template. The def function outputs 1 if a value is empty or 0 – handy for quantities.
{# EXEC
def = (val) => val ? val: 1;
#}
The structure of your table:
| Material | Unit | Quantity | Item number |
|
{# FOR item IN field("taskID/listID") #} |
|
|
|
|
{# $item.asset #} |
{# $item.values.attributeID #} |
{# def($item.values.attributeID) #} |
{# $item.values.attributeID #} |
|
{# END-FOR item #} |
You can simply write each piece of code on one line – the line breaks here only appear because the table is too narrow.
Objects from lists within measurements
In your measurements, you can add objects to your measurement points – typical examples are components or service items that should be located on individual parts of the measurement.
{# FOR measurement IN field(“taskID/fieldID”) #}
| Point number | Name | Length | Width |
|
{# FOR item IN $measurement.items #} |
|
|
|
|
{# $item.featureId #} |
{# $item.asset #} |
{# $item.values.Length #} |
{# $item.values.Width #} |
|
{# END-FOR item #} |
{# END-FOR measurement #}
Checkbox values from fields
Here, too, you need to add a command before (or above) the checkbox:
{# EXEC
jaNein = (v) => (v? "Ja": "Nein");
simple = (v) => (v? "X": "_");
retro = (v) => (v? "☒": "☐");
#}
To retrieve a box:
{# jaNein(field("taskID/boxID")) #}
In your command, you can replace jaNein with simple or retro to change how it's displayed. jaNein outputs the German words "Ja" (yes) and "Nein" (no). If you'd like English output, simply replace "Ja" and "Nein" in the EXEC block with "Yes" and "No".
Checkbox values from lists
You can export checkbox values from lists in much the same way. Here, too, place the code from above before (or above) the list:
{# EXEC
jaNein = (v) => (v? "Ja": "Nein");
simple = (v) => (v? "X": "_");
retro = (v) => (v? "☒": "☐");
#}
Then create a list again, just as you did for values from lists:
| Material | Defect-free | Installed? | Satisfied? |
|
{# FOR item IN field("taskID/fieldID") #} |
|
|
|
|
{# $item.asset #} |
{# jaNein($item.values.boxID) #} |
{# simple($item.values.boxID) #} |
{# retro($item.values.boxID) #} |
|
{# END-FOR item #} |
In the individual attribute cells, you can then choose how a ticked (or unticked) box is displayed: with jaNein, simple or retro. Again, replace boxID with the correct ID of the box you want to query there.
Syntax for conditions
You can also set up your export template so that certain values – such as a 0 – aren't exported at all.
In the following commands, too, you only need to adjust the values in bold; the rest is general command code and must not be changed.
Showing (or hiding) specific values in the export
IF query with values (1st case IF NOT EQUAL, 2nd case IF EQUAL):
{# IF field("taskID/fieldID") != 0 #}
{# field("taskID/fieldID") #}
{# END-IF #}
{# IF field("taskID/fieldID") == 1 #}
{# field("taskID/fieldID") #}
{# END-IF #}
== means equals.
!= means does not equal.
> means is greater than.
< means is less than.
When comparing with words, it's important to put them in quotation marks (as with "Rohr", German for pipe). You can query numbers without quotation marks.
{# IF field("taskID/fieldID") == "Rohr" #}
{# field("taskID/fieldID") #}
{# END-IF #}
Syntax for formatting
Setting the number of decimal places
The value in the brackets determines how many decimal places are shown. The number is rounded.
{# field("taskID/fieldID").toFixed(3) #}