Use conditions in the Output template

Posted on

Conditions are useful when the software where you need to put data requires to perform a sequence of actions only when a condition is verified.

 

The components required to make it happen are the if and the endif component. Their job is to change the flow of execution of the Output template.

 
 
 

If the condition is true, the if component allows the flow of execution to continue with the next component.

But if the condition is false, if causes the flowof execution to skip to endif, from which point execution will proceed.

 
 

Example

Let’s say that you need to put the barcodes that do not start with “9” into another column:

 
 
 

In that case the output template would like something like this:

  1. The first component acquires the barcode and stores its value in the global variable called “barcode”.

    The checkbox is unchecked because we want to skip the output of this component.

  2. The IF component will perform the check over the “barcode” variable.
    • If the condition is true, it’ll allow the flow of execution to continue with the next component that will acquire the second barcode.
    • But if the condition is false, it’ll cause the flow of execution to skip to ENDIF component, from which point execution will proceed.

Tip: If you want to add a delay between the acquisitions you can do that by increasing the “Timeout” option from the app settings.

Syntax

To edit the if component, you simply need to click over it: if

The if component accepts the JavaScript syntax. The result of the expression that you put inside the component will be evaluated in the exact same way of a standard JavaScript code snippet.

You can find some string manipulation examples here: JavaScript String Methods.

Available variables

The IF can access to the following variables:

  • barcode
  • quantity
  • timestamp
  • device_name

Life cycle

The IF component is evaluated on the app side when a scan is performed, more in particular when the app is populating Output template.

More condition examples

As already said you can use any JavaScript code you want, so you can do things like:

  • barcode.endsWith("US")
  • quantity == 1
  • timestamp > new Date().getTime() * 1000
  • device_name == "John's iPhone"

Comments

No comments found. Be the first to leave a comment.

Your email address will not be published. Required fields are marked *

Related posts