Printing Database Records through a Web Service Integration in a Single Print Job
Chances are you are looking into creating a Web Service Integration to take advantage of the bi-directional communication that allows us to report back more information about how the trigger file is received. Furthermore, you may be sending variable data for BarTender to use for each of the labels that you want to print. However, you may not like that for each single record of data that you send that an individual print job is made for each one. Some customers also have situations where the printer needs to perform a task in between print jobs, which would significantly increase the overall time to print when obtaining your desired quantity of labels.
This example method allows us to take advantage of the trigger processing of a Web Service Integration but also takes your desired records to print and creates a single print job for them through the use of Print Command Script.
The best way to think about any integration is to at least split the events happening into two: the event triggering the integration, and events to take place after the trigger is received. The article here all about Can I send multiple records in a web service integration? talks about the first half of the integration. As it states, you can set up a POST web service integration and send multiple records much like the image shows:
Note that this is simply one method where the user chose to place not only their relevant data, but also chose to define the label and the printer each record. You may want to explore a different avenue. For example, this is how I structured my data to be sent to the integration:
The tricky part (and honestly what makes Integration Builder such a powerful tool) is what to do after you have sent the information to the integration. At this point, the web service integration doesn't have any idea what this data is or what it is used for. We want to somehow package the records we sent into some sort of record set. Then if we do that, we can print our desired document using our dynamically created database.
Here are the sample files you can use to follow along with this tutorial or you can create your own:
- TESTDB.txt - sample database for use in the label
Create a Sample Database File
To start, create a sample database that will reflect how you will be sending your data from the integration. In this example, I will be sending two pieces of data per label I want to print: the Tracking Number and the Serial Number. Thus, I created a comma delimited text database like so and saved it as TESTDB.txt:
Create the BarTender Document
We need to prepare the label to accept the Tracking Number and Serial Number that we will be sending through the integration by associating the database connection to the appropriate objects.
- Open ShippingLabel.btw.
- Connect your database (TESTDB.txt) to BarTender using the Database Connection Setup option in BarTender (you can use this as a reference: Getting started with database connections (Video - 5:20))
- Associate your record's Header Fields to your desired objects on in your label template (also covered in the referenced support article)
- Save the label.
Create the Integration
We now need to create the integration. Since this example will be using a POST request method, we will want to create a Web Service Integration
- Open Integration Builder
- Select Create New Integration
- Select Web Service as the desired integration option, then click OK.
- Under Input Data, ensure that the Input Data Format is set to Unstructured.
- Under Response, go ahead and write back any desired response that you want to send. Here is an example response that you can use:
Print Job Status = %PrintJobStatus%
Print Job Messages = %PrintJobMessages%
- Under the Actions, delete the Print Document action by clicking on the red X to the right of the action. Then, click on the blue plus button to gain access to the different actions you can take in any integration:
- Add three Actions:
Transform Text to Record Set
Print Command Script
- In the Transform Text to Record Set command, adjust the following:
Under Text Database Connection Configuration option, connect the TESTDB.txt to the integration.
Ensure that the Text Source is set to Variable and %EventData%
Ensure that the Output is set to save the record to the %EventData% variable
- In the Write File command, adjust the following:
Set the Source to Variable %EventData%
Set the Destination of the database file that we are about to write to a desired location. Make sure that wherever you save this file that your integration will have high enough user permissions to access that location. This example places the file under C:\test.
Name the file whatever you like. The next step will need that filename.
Choose what you would like to do if the database file you write already exists. This example chose to Replace file if it already exists.
- In the Print Command Script command, adjust the following:
Choose the Source to be Embedded Script.
In the Script window, write out the following:
For the Print Option Overrides, check the box for Prompt for data input.
%BTW% /AF="C:\test\ShippingLabelMod.btw" /D="C:\test\TestResult.txt" /P
Test the Integration
Before deploying your integration, you want to ensure that this integration works! Use the Test Integration option in Integration Builder by either clicking on the icon in the Home menu or by clicking on the Test tab next to Properties towards the bottom of your Integration Builder window.
REST Client Setup
- We will need to use a REST client to test sending a POST request to BarTender. You can use whatever REST client you wish. In this example, we chose to use Insomnia, which you can download here: Insomnia Rest Client
- Once you have the REST Client installed, go ahead and create a new POST request, using "other" as the text formatting option.
- Go ahead and input the following data. In a way, our request is structure like it is a database, where each record is on its own line. With this example, we will be printing five labels where each line represents the Tracking Number and Serial Number, respectively, just like the example database represented in TESTDB.txt.
- Edit the website address to use the address that will reference and trigger the integration. It should say something like this:
You can find this inside of the Service tab within the integration. The <host> will be the hostname of your computer. If you are unsure of what this might be, open Command Prompt, type in "hostname" without quotations, and press Enter.
Here is where you would enter that full URL path with your hostname:
Testing the Integration
- Click on the Test Integration option in the Home menu.
- Click on the Start button to the top right hand side of the testing window. Your integration should now start.
- In your REST Client, click Send. It will take a couple of seconds, but soon you will see not only a response back in your REST Client, but also inside of the integrations test window:
Deploy the Integration
- From the Integration Builder toolbar, click Deploy Integration to open the New Deployment dialog.
- In the New Deployment dialog, enter a name and description for your deployment.
- Ensure that the Integration File setting lists IntegrationFile.btin (or whatever name you saved your integration as).
- For Target Servers, add the server(s) you want to deploy the integration file to.
- Specify the desired Error Handling settings.
- Click OK to close the dialog and deploy the integration file.
- Administration Console will open on the Integrations node, displaying your integration.