In this Connected Learning Path, we will create a Chain that illustrates how to leverage the Handlebars Connector to parse data from an HTTP response and templatize variables that can be used throughout a Chain.
| Primary Learning Objective | Handlebars Command Capabilities |
| Secondary Learning Objectives | Workiva Chains Connector |
| Prerequisites | Configure Handlebars Connector connection. Configure Workiva Chains Connector connection. |
| Supporting Template | CLP | Handlebars Configuration |
Step 1: Create a Chain
- Add a new Chain.
- Name the Chain CLP | Handlebars Configuration.
- Create a Chain variable. Enter the following values for the variable name and value:
- Variable Name: cv-AllStations
- Variable Value: https://cs-sftp-training-bucket.s3.amazonaws.com/cs-training/transformation-qs/station_information.json
- Save the Chain.
Step 2: Retrieve JSON Data
This step uses the HTTP Connector to retrieve Citibike-related data in JSON format from a web location.
- Add a GET Command from the HTTP Connector to the Start node.
-
Configure the Command using the following values:
Name GET - All Stations User Name <leave blank> Password <leave blank> CA Certificate <leave blank> Certificate <leave blank> Certificate Private Key <leave blank> Show Response Checked URL cv-AllStations Chain Variable Query string <leave blank> Content type application/json Response <leave blank> - Save the Command.
Step 3: Iterate through the JSON data
Use the Handlebars - Render Text template Command to iterate through the CitiBike station data to provide a format that provides each individual stations data combined.
- Add the Handlebars - Render Text Template Command to the Chain canvas.
- Connect the GET - All Stations Command to the Handlebars - Render Text Template Command.
- Double-click the Command to edit it.
- Name the Command: RTT - Parsing JSON Response.
- Add a JSON Variable and name it citibikeData.
- For the Value field use the Response variable from the Get - All Stations Command.
-
Fill out the template field with the following value:
{{#each citibikeData.data.stations}} {{@index}} | {{name}} | {{capacity}} {{/each}}This will allow the Command to iterate through the JSON response, using a root path of
data.stationsto provide text values from each key: (“name”, “capacity”). In addition, it will add an index value for each row processed.
- Save the Command.
Step 4: Templatizing Runtime Variables
Use the Handlebars - Render Text Template Command to templatize variables. This will allow the Chain to render a text template that provides context on different components of the Chain based on its runtime.
- Add the Handlebars - Render Text Template Command to the Chain canvas.
- Connect the GET - All Stations Command to the Handlebars - Render Text Template Command.
- Double-click the Command to edit it, using the following values:
- Name the Command: RTT - Templatizing Variables.
- Add and populate the following information for the variables section:
The Value fields will be populated from the Runtime dropdown of the left variables pane.-
Variable 1
- Variable Name: Chain-Env
- Value: <Chain.Enviroment> (Runtime Variable)
-
Variable 2
- Variable Name: Chain-Exec-Time
- Value: <Chain.ExecutionDateTime> (Runtime Variable)
-
Variable 3
- Variable Name: System-RunTime-Month
- Value: <System.DateTime> (Runtime Variable)
- Click on the <System.DateTime> runtime variable to transform the variable.
- On Select Transformation, choose Parse Date/Time, and click the “+”.
- In the first value field, choose “ISO Extended (Platform Standard)".
- In the Output date format field, enter “%m”.
- In the Input date timezone field, choose “UTC (Etc/UTC)”.
- In the Output date timezone field, choose “UTC (Etc/UTC)”.
- Click Accept.
-
Variable 4
- Variable Name: System-RunTime-Year
-
Value: <System.DateTime> (Runtime Variable)
- Click on the <System.DateTime> runtime variable to transform the variable
- In Select Transformation, choose Parse Date/Time, and click the “+”.
- In the first value field, choose “ISO Extended (Platform Standard)".
- In the Output date format field, enter “%Y”.
- In the Input date timezone field, choose “UTC (Etc/UTC)”.
- In the Output date timezone field, choose “UTC (Etc/UTC)”.
- Click Accept.
-
Variable 1
- Fill out the template field with the following values:
- Chain Environment: {{Chain-Env}}
- Chain Execution Date: {{Chain-Exec-Time}}
- System Runtime Month-year: {{System-RunTime-Month}}-{{System-RunTime-Year}}
- Save the Command.
Step 5: Templatizing Workspace Variables - Get Workspaces
Use Handlebars - Render Text Template to templatize components of a Workspace. This will allow the Chain to render a text template that provides context from different components of the Workspace that the Chain is located in.
- Add the Get Workspaces Command from the Workiva Chains connector to the Chain canvas.
- Connect the GET - All Stations Command to the Get Workspaces Command.
- Double-click the Command to edit it, and confirm that the connection is correct.
- Save the Command.
Step 6: Templatizing Workspace Variables - RTT - WorkspaceID
- Add the Handlebars - Render Text Template Command to the Chain canvas.
- Connect the Get Workspaces Command to the Handlebars - Render Text Template Command.
- Double-click the Command to edit it.
- Name the Command RTT - WorkspaceID.
-
Enter the following value into the Template field:
{{#each workspaces}} {{#if (equal name "<(chain.workspace)>") }} {{id}}{{/if}}{{/each}}
- Select the <Chain.Workspace> variable from the runtime variables section in the left panel
- In the JSON Variables field, enter the following information:
- Variable Name: workspaces
- Variable Value:: <Workspaces>
- Expand the Get Workspaces variable from the variables panel on the left and select Workspaces.
- Save the Command.
Step 7: Templatizing Workspace Variables - Get Environments
- Add the Get Environments Command from the Workiva Chains Connector to the Chain canvas.
- Connect the RTT - WorkspaceID Command to the Get Environments Command.
- Double-click the Command to edit it, and enter the Rendered Text variable from the RTT-WorkspaceID Command within the Workspace ID field.
- Save the Command.
Step 8: Templatizing Workspace Variables - RTT - EnvironmentID
- Add the Handlebars - Render Text Template Command to the Chain canvas.
- Connect the Get Environments Command to the Handlebars - Render Text Template Command.
-
Double-click this Command to edit it, using the following values:
- Name the Commmand: RTT - EnvironmentID.
-
Enter the following value into the Template field:
{{#each environments}} {{#if (equal name "<(chain.environment)>") }} {{id}}{{/if}}{{/each}}The
<Chain.Environment>is a Runtime variable, and can be found on the left panel. - In the JSON variables field, enter the following information:
- Variable Name: environments
-
Variable Value: <Environments>
This value is found on the left variable panel under the Get Environments Command.
- Save the Command.
Step 9: Test the Exercise
- Publish the Chain.
- Click Execute, and then select Run Chain.
- Once the Chain has completed its run:
Confirm that all nodes were successfully executed by click on the executed RTT - Parsing JSON Response Command and verifying that the first few lines of the output is as follows: -
Click on the executed RTT - Templatizing Variables Command, and verify that the rendered text is accurate within the “Logs” tab.
Note: These values will change based both on the Environment that the Chain is run in and when it is run.
- Click the RTT - Environment ID node and select the Outputs tab.
- Confirm that a value has populated for the rendered text variable (again, this result will vary depending on your Environment).
Learning more
To learn more about data transformation using Chains, check out Connected Learning Paths - Transformation Introduction