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
- Name: cv-AllStations
- Value: https://cs-sftp-training-bucket.s3.amazonaws.com/cs-training/transformation-qs/station_information.json
- Save the Chain
Step 2: Retrieve JSON Data
We use the HTTP Connector to retrieve city bike related data in JSON format from a web location.
- Add a GET Command from the HTTP Connector to the Start node
- Configure the Command with the following:
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 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.stations to provide text values from each key: (“name”, “capacity”)
- Additionally, it will add an index value for each row processed
- This will allow the Command to iterate through the JSON response, using a root path of data.stations to provide text values from each key: (“name”, “capacity”)
-
- Save the Command
Step 4: Templatizing Runtime Variables
Use the Handlebars - Render Text Template to templatize variables. This will allow the user 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
- 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
- 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
- On Select Transformation, choose Parse Date/Time
- 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
- Fill out the template field with the following value
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 the Handlebars - Render Text Template to templatize components of a Workspace. This will allow the user 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
- Double check 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:
- Name the Command “RTT - WorkspaceID”
{{#each workspaces}}
{{#if (equal name "<(Chain.Workspace)>") }}
{{id}}{{/if}}{{/each}}
-
- Select the <Chain.Workspace> variable from the runtime variables section in the left panel
- Add a JSON Variable
- Fill in the following information:
- Name: workspaces
-
Value: <Workspaces>
- Expand the Get Workspaces variable from the variables panel on the left and select Workspaces
- Fill in the following information:
- 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
- Add 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 the Command to edit it
- Name it “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, found on the left panel
- Add a JSON Variable
- Fill in the following information:
- Name: environments
- Value: <Environments>
- This is found on the left variable panel under the Get Environments Command
- Fill in the following information:
-
- Save the Command
Step 9: Test the Exercise
- Publish the Chain
- Click Execute and then select Run Chain
- Once the Chain has completed:
- Confirm that all nodes were successfully executed
- Click on the executed RTT - Parsing JSON Response command
- Verify that the first few lines of the output is as follows:
- Click on the executed RTT - Parsing JSON Response command
- Confirm that all nodes were successfully executed
-
-
- Click on the executed RTT - Templatizing Variables Command
- Verify that the rendered text is accurate within the “Logs” tab
- Click on the executed RTT - Templatizing Variables Command
-
-
-
-
- These values will be change based on which Environment 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 (this result will vary depending on the user’s Environment)
-
-
To learn more about data transformation using Chains, check out the Connected Learning Paths - Transformation Introduction!