Value expressions

In this tutorial you will learn how to use the value expression editor. Each text element, barcode or two-dimensional code is designed to represent a value. You can set, program or calculate this value with the editor discussed in this tutorial.

Open the label template editor

You can use an existing template or create a new one for this tutorial. If you don’t know how to do it or you would like to learn basic information about the sizes and positioning of elements on the label, check out this this tutorial first.

What are value expressions

As mentioned before, each text element, barcode or two-dimensional code is designed to represent a value. You may want to create a text element witch will act as a static label, dynamically changing variable representation or you may need to modify your data before printing, add some prefix, cut the text or make it uppercase. It is also possible to join static text, dynamic variables (placeholders) and use functions at the same time. All of these tasks can be achieved using the value expressions editor.

Open value expression editor

Add simple text element to the label template. When active, notice field Value expression on the element’s option panel. Click the pen icon to open the editor. As you can see, default static text value is set for each new text element.

Value expression editor controls

With value expression editor you can add and remove parts of your expression as blocks of the expression using the plus and trash icons. After you finish building an expression, you should save it with Confirm button. Please notice meaning of the colors presented in the editor. They help you recognize purpose and type of each of the block. You can use static text, placeholder and function blocks. During expression assembly, you can also see the results in real time preview at the top of the expression editor.

Add new block to value expression

Please open the expressions value editor and try to add new static text expression using the plus icon next to the last block in editor. Enter random string in the static value field and confirm with round plus icon. Notice how the block is added to the expression and in preview.

Remove block from value expression

Please open the expressions value editor and try to remove one of the blocks. To do that, hover over the block you want to remove. You will see the red trash icon near the block. Use this trash button. Notice how the block is removed from the expression and preview.

Static text

Static text is mainly used to print fixed, immutable label elements. A good example would be the description of a dynamic text field or barcode. If you want to title one of your label fields, create a text element and create a static text expression for it, for example “Product code“.

Create text field used as “Product code” title

  1. Add new text element to sing _trash icon.
  2. Click plus icon to add new expression block choosing Static text type.
  3. Type Product code in the Static value field.
  4. Click the round plus button (notice new block in editor and new value in preview section).
  5. Click Confirm button in the editor.

Your Product code title field should be ready.

Placeholders

Placeholders represent dynamic values in the label template that will change for each printout. These variables will be provided depending on the method of managing printouts, by entering the data in the appropriate Excel form or by sending them in json format to the REST endpoint.

When designing a label, add placeholders to the template and give each of them a meaningful name, that will allow you to easily identify them in value expressions. It is also mandatory to set a preview value for each placeholder. This value will be displayed as expression value when designing your templates and will be replaced with the provided data during production use. Note that the placeholder cannot be shown as a separate element in the label. It is always part of the value expression of one of the elements such as text elements or barcodes.

Create a barcode representing the product code

  1. Add new Code-39 linear barcode element to your template and set some name to help you identify it.
  2. Add new text placeholder in the bottom left panel of editor (double T icon).
  3. Select new placeholder in the list and set parameters in the right element options panel:
  • set name as productCode
  • as preview value type whatever code you want here
  1. Click on a previously created barcode element and open its value expression editor.
  2. Remove default text block using trash icon.
  3. Click plus icon to add new expression block choosing Placeholder... type.
  4. Open the Choose placeholder list. You should be able to locate your productCode placeholder there.
  5. Click the round plus button (notice new block in editor and new value in preview section).
  6. Click Confirm button in the editor.

Your Product code barcode field should be ready and should present the preview value of your productCode placeholder.

Functions

Sometimes you will need to modify the data before printing it on the labels. For example, you may need to add a prefix to each barcode to help the WMS recognize the field type. You may also want to limit the length of the text to a certain number of characters. Otherwise, you may want to format the date, extract part of it, or make the text uppercase, lowercase, or capitalize each word. All these tasks can be achieved with expression editors built-in functions.

In the examples above we created a static text element with “Product code” title and a barcode element containing the actual product code. Please notice, that the barcode element converts it’s value to upper case. But what if you also need to print human-readable product code, and you want to present the code in capital letters, but you are not sure if the data you get will be properly prepared? The following example fixes this problem.

Create a text element representing the uppercase product code

We will use the productCode placeholder from example in previous section. If you didn’t follow this tutorial before, add new text placeholder with the mentioned name or reference previous section.

  1. Simulate productCode placeholder’s preview value to be invalid. Set its preview value to some lowercase string (for example: p100rm23)
  2. Add new text element to your template and open corresponding expressions value editor.
  3. Remove default text block using trash icon.
  4. Click plus icon to add new expression block choosing Function... type.
  5. From the functions list, choose the toUpperCase function.
  6. Click the round plus button (notice new block in editor and new warning in preview section).
  7. The function block allows you to add function’s arguments below the block. toUpperCase expects only one argument, the text that should be converted to uppercase.
  8. Click the plus button below the function’s value argument and choose placeholder type, then select your productCode placeholder.
  9. Click the round plus button (notice new velue block below function block in editor and new uppercase value in preview section).
  10. Click Confirm button in the editor.

Your Product code text field should be ready and should present the preview value of your productCode placeholder converted to uppercase.

Connecting all the elements together

As you probably noticed looking at the screenshot at the beginning of this tutorial, the value expressions can be quite complex and can mix all the features mentioned in this tutorial all together. Although in most cases it probably will not be needed to build such a complex expressions, it is good to know how to do this. With the knowledge you gained in previous sections, try to prepare one new text field which will use four placeholders. Set the new placeholders’ names and values as below. Please notice the lowercase product code and first and last name.

  1. productCode: p100rm23
  2. productDescription: A long and very detailed description that can not be printed in full length
  3. speditorFirstName: john
  4. speditorLastName: doe

Now let us remind you the target expression:

We want to create the expression which will join and format the given data to produce value containing

  1. some static text fragments
  2. set product code to uppercase
  3. cut a long description value to 15 characters
  4. capitalize the first letter of the speditor’s first name
  5. set whole speditor’s last name to uppercase

Create a text element representing the uppercase product code

To build expression, follow the steps:

  1. Add new text element to your template and open corresponding expressions value editor.
  2. Remove default text block using trash icon.
  3. Add static text “Info: ” – please notice space at the end.
  4. Add toUpperCase function and set its value with productCode placeholder.
  5. Add static text “-” – please notice space at beginning and at the end.
  6. Add abbreviate function and set its value with productDescription placeholder and max size value with static text 15.
  7. Add static text “From:” – please notice space at beginning and at the end.
  8. Add capitalizeWords function and set its value with speditorFirstName placeholder.
  9. Add static text “ ” – one character: space.
  10. Add toUpperCase function and set its value with speditorLastName placeholder.
  11. Click Confirm button in the editor.

The final effect should look like this:

Info: P100RM23 - A long v... From: John DOE

Table of contents