Adding a barcode
We want the letter to have a QR barcode that opens a URL with a data field value. This chapter demonstrates various ways to add the data field value to the URL.
1. Adding a QR code
- Position the cursor at the end of the document.
- Choose Insert > Barcode... > QR Code. The Insert Barcode dialog appears.
- From the Field drop-down, select first_name.
- Change the ID into
QRcode
. - Click OK to insert the barcode.
-
Now click the barcode box, hover over an edge so that the cursor changes, then click again and drag the box to the bottom right corner of the page.
- Toggle to Preview mode and use the browse buttons in the Value column to browse through the imported data.
2. Adding a URL to the barcode: Helper
The QR code is now based on the value of the first_name data field, but we want it to contain a URL that has the value of the first_name field as parameter. One way to construct such a URL is by using the Handlebars Helper wizard.
The Handlebars Helper wizard creates a Helper that concatenates multiple data fields and that can add a prefix and/or suffix to each data field.
Note: A Helper is a function that can be used in an expression.
-
Open the Handlebars Text Helper wizard: on the Scripts pane at the bottom left, click the black triangle on the New button and click Handlebars Text Helper. The Edit Text Helper dialog appears.
-
Change the name of the Helper so that it clearly describes the purpose of the script (e.g. setBarcode). The name must be unique.
-
The Handlebars Text Helper wizard allows to select one or more data fields. Each field is placed on its own line in the wizard. New lines can be added by clicking the Plus sign next to the table or simply by clicking on the next empty line.
In the Prefix and Suffix fields you can add text to be combined with the data.Enter the following on the first line:
Prefix https://olresourcecenter.uplandsoftware.com/?salutation=Hello%20 Data field first_name Suffix , Tip: For a line break, you can click the Prepend line break or Append line break icon.
You can type for a space that needs to go into the text of the template.
- On the Properties tab, change the Scale to Proportional, so that the QR code will fit in its box.
- Click OK. The name of the script, setQRUrl, is added to the Scripts pane under the Standard scripts folder
- Change the text inside the QR Code from {{first_name}} into {{setQRUrl}}.
-
Toggle to Preview mode and try the QR code.
2. Adding a URL to the barcode: script
Normally, one of the big advantages of the Handlebars Helper wizard is that empty lines and spaces are automatically removed when data fields have no value.
Note: When a data field is empty the respective line is skipped including its prefix and suffix.
However, in this particular case, we want the QR code to have the URL even if the first_name data field is empty. This is better done with a script.
-
On the Scripts pane at the bottom left, click the black triangle on the New button and click Standard Script. The Edit Script window appears.
The Script Editor allows to select elements in a template and apply an action to them. The selection is not limited to items inside sections; scripts may also control other elements, such as elements on master pages.
Actions include changing styles and formatting, hiding, or removing elements, replacing elements and injecting content (from HTML snippets, for example).
-
Change the name of the script so that it clearly describes the purpose of the script (e.g. setQRUrl). The name must be unique.
-
In the Selector field, type
#barcode
. This refers to the ID of the barcode which you set when adding the barcode. -
Type the following script.
Copylet myUrl = "https://olresourcecenter.uplandsoftware.com/?salutation=Hello "
+ record.fields.first_name
results.text(myUrl)Note: In OL Connect Designer all scripts are written in JavaScript, a scripting language that was originally developed to create interactive web pages. For this walkthrough you don’t need to know anything about JavaScript – you may copy the script - but it will pay off to learn the basics.
- Click OK.
- Toggle to Preview mode and try the QR code.
-
Both the Helper and the script have an effect on the QR code, but the effect of the Helper is no longer visible: it is overwritten by the output of the standard script. You can see this in the code when you scan it: there is no comma at the end of the URL.
This is due to the order in which scripts are executed. Control scripts are executed first; then come the Standard Scripts.To keep the template clean it is better to remove the Helper and the expression in the QR code.