Capture OnTheGo flows in Node-RED
Capture OnTheGo is an OL Connect solution that allows to create and send digital forms to the COTG App(iOS, Android or Windows 10) and processes any data that is returned by the app after a form has been filled out.
A Capture OnTheGo solution typically consists of three basic flows.
-
The flow that makes a document available to COTG App users.
-
The flow that replies to document requests from COTG App users.
-
The flow that receives data from Capture OnTheGo App users.
A Capture OnTheGo Repository ID and password are required in order to configure the COTG node in these flows.
Making a form available to COTG app users
The flow that creates and publishes COTG forms will usually have the following nodes.
-
Typically the trigger will be an endpoint set up using the http in node, but the flow could also be triggered by an input node like the OL Connect capture folder node, the standard watch node or the third-party watch-directory node (see Nodes used in OL Connect flows).
-
In order to create a personalized form or document, incoming data must be processed.
Once the data file is received, the data mapping node uploads it to the Connect Server and subsequently extracts the data using a data mapping configuration. It outputs a data set ID inmsg.dataSetId
. -
The data get node retrieves the records from the database using the data set ID. It stores the retrieved data records in an array on
msg.payload
. -
Node-RED's split node can be used to iterate over the records. In each iteration the record values of a single record are written to
msg.payload
. -
A change node sets any
msg
properties that the file node and the cotg publish node need, such as the order ID, customer name, COTG account and the file name of the form. -
OL Connect's html content node takes the record ID in
msg.payload
as its input and renders the form. It outputs the HTML tomsg.payload
. -
The file node writes the HTML content in
msg.payload
to disk. -
The cotg publish node informs the Capture OnTheGo Server that a new document is available for download. The node returns the ID of the form on the COTG server in
msg.documentId
.Store the form ID in a text file or database along with the order ID and/or GUID. This makes it possible to find and delete the form (using the cotg delete node) when form data is submitted.
Serving the form
As soon as a COTG app user taps a button to download a new form, the second flow springs into action to serve the requested COTG form.
-
The http in node receives the request from the COTG app.
-
A change node can be used to construct the path to the form file (see Concatenating strings) and store it in
msg.filename
. -
The file node reads the file from the location given in
msg.filename
. The form data is returned inmsg.payload
. -
The http response node sends the response back to the request received from the http in node.
It is recommended to add a catch node to catch any errors thrown by the file node and return the applicable error code to the browser.
Although it is possible to design the flow to produce the form on demand, this can negatively affect response time because the template must be merged with data first.
Processing received data
The last required flow in a Capture OnTheGo solution will have an http in node set up to receive data from the COTG app.
The data may be processed in a variety of ways, as required.
In order to make the COTG app delete the form from the device's library upon successful transmission of the data, the flow must return status code 291 via the http response node.