In this exercise, we will create a Chain that illustrates how to dynamically account for a leap year.

Primary Learning Objective

To highlight the power of Variable Transformation for date operations including parsing, formatting and performing math-based operations.

Secondary Learning Objectives

To highlight the use of Runtime Inputs, Handlebars, and JSON parsing in Variables.

Prerequisites

Configure Handlebars BizApp Connection

Supporting Template

Variable Transformation: Date Operations


Step 1: Create a Chain

  • From the Sample Workspace for Transformations Workspace, select the DEV Environment.

  • Add a new Chain.

    • Name the Chain, Transformation QS - Variable Transformation: Dates.

  • Save the Chain.


Step 2: Add a Runtime Input

Runtime Inputs illustrate how a Chain can prompt for values at execution. This is a valuable way to make Chains able to be used across multiple processes.

📓 The videos for this step have been broken into three (3) parts for simplicity. However, the process is continuous and may be performed all at once.

Part I - Create the Command

  • Add a Runtime Inputs to the Start node.

    💡 Use the Search bar to search for "runtime". Then double-click to autoload the Command into the Start circle.

  • Click Add Input and select DropdownField.

  • Configure the DropdownField with the following:

Display Name

Month

Required

Checked

Description

Select the current month

  • Click Add Option

  • Configure with the option with the following:

Value

{"display":"January","value":"01-01"}

Display Name

January

Default

Not Checked

Part II - Complete the Dropdown Field

  • Add options for the remaining eleven months of the year. Update the Value and Display Names accordingly.

    • Example:

      {"display":"February","value":"02-01"}

Part III - Include a NumberField

  • After completing the DropdownField input, add a NumberField Input

  • Configure the NumberField with the following:

Display Name

Year

Required

Checked

Description

Enter the current year in YYYY format

Default Value

<leave blank>

Min Value (Checked)

2000

Max Value (Checked)

2050

  • Save the Runtime Input


Step 3: Add a Command to Create a Period Key

We use the Handlebars BizApp to take the values specified in the Runtime Inputs and create a period key in YYYY-MM-DD format.

  • Add a Render Text Template Command from the Handlebars BizApp to the Chain.

  • Connect the Start Node (Runtime Inputs) to the Render Text Template Command.

  • Edit the Command.

  • Name the Command: Render Text Template - Create Period Key.

  • In the Template parameter, enter the following:

{{Year}}-{{Period}}
  • Add two variables by clicking the Add button twice on the Variables section.

  • For the first variable, specify the Variable Name as Year.

    📓 Variable names are Case-Sensitive.

  • Click in the Value field.

    • In the Variable pane, expand Trigger ➡️ Runtime Inputs and select Year.

  • In the second variable, specify the name as Period.

  • Click in the Value field.

    • In the Variable pane, expand Trigger ➡️ Runtime Inputs and select Month.

  • Click the Month variable (as denoted by the bubble) that was assigned to the value.

    • Click the Select transformation dropdown

      • Select Parse text as JSON

      • Click the plus (+) symbol.

    • Click the Select transformation dropdown again

      • Select Get Value from JSON

      • Click the plus symbol.

    • In the Get Value from JSON line,

      • From the Output column's dropdown, select "T".

        📓 The T is the month variable that was established in the prior step.

      • In the Value column's field, enter "value" and press the Enter key.

      📓 The text value must be in lower case and will appear as a grey bubble after pressing the Enter key.

    • Click Accept.

  • Save the Command.


Step 4: Add a Command to Perform Date Operations

📓 The videos for this step have been broken into four (4) parts for simplicity. However, the process is continuous and may be performed all at once.

Part I - Add Command & Template

We use the Handlebars BizApp to perform several date operations including date math and reformatting.

  • Add a Render Text Template Command from the Handlebars BizApp to the Chain.

  • Connect the Render Text Template - Create Period Key Command to the Render Text Template Command.

  • Edit the Command.

    • Name the Command: Render Text Template - Date Parsing.

    • In the Template parameter, enter the following:

      Time Period Selected:
      Month: {{Month_Name}}
      Year:
      Period Key: {{Period_Key}}
      End of Month Period Key: {{EOM_Key}}
    • In the Template parameter section

      • Click after Year

      • Then expand Trigger ➡️ Runtime Inputs and select Year.

Part II - Add First Variable

  • Add three variables by clicking the Add button on the Variables section.

    • For the first variable:

      • Specify the first Variable Name as Month_Name.

        • Click in the Value field.

          • In the Variable pane, expand Trigger ➡️ Runtime Inputs and select Month.

        • Click the Month variable's bubble in the Value field.

          • Click the Select transformation dropdown

            • Select Parse text as JSON, and click the plus (+) symbol.

          • Click the Select transformation dropdown again.

            • Select Get Value from JSON, and click the plus (+) symbol.

              • In the Get Value from JSON line, select T from the Output dropdown.

              • In the same Get Value from JSON line, enter display in the Value field and press the Enter key.

          • Click Accept.

Part III - Add Second Variable

  • For the second variable:

    • Specify the Variable Name as Period_Key.

      • Click in the Value field.

        • In the Variable pane, expand Render Text Template - Create Period Key

          • Select Rendered Text.

      • Click the Rendered Text variable's bubble in the Value field.

        • Click the Select transformation dropdown and select Parse Date / Time, and click the plus (+) button.

        • In the first dropdown box, enter %Y-%m-%d and be sure to press Enter.

        • In the Output date format field, enter %m/%d/%Y.

        • In the Input date timezone dropdown, type UTC and then select the (UTC) Dublin, Edinburgh, Lisbon, London timezone.

        • Repeat the UTC selection for the Output date timezone field.

        • Click Accept.

Part IV - Add Third Variable

  • For the third variable:

  • Specify the Variable Name as EOM_Key.

    • Click in the Value field. In the Variable pane, expand Render Text Template - Create Period Key and select Rendered Text.

    • Click the Rendered Text variable that was assigned to the value.

      • Click the Select transformation dropdown and select Add / Subtract Date and Time, and click the plus (+) symbol.

        • In the Format dropdown box, enter %Y-%m-%d and be sure to press Enter.

        • In the Operation dropdown, select Add.

        • In the Amount field, enter 1.

        • In the Unit dropdown, select Month.

      • Add an additional Add / Subtract Date and Time transformation

        • In the Format dropdown box, enter %Y-%m-%d and be sure to press Enter.

        • In the Operation dropdown, select Subtract.

        • In the Amount field, enter 1.

        • In the Unit dropdown, select Day.

      • Output date timezone field.

      • Click Accept.

  • Save the Command.


Step 5: Test the Chain

Now that the Chain is complete, we can test the result.

  • Publish the Chain.

  • Click Execute and then select Run With Inputs.

  • From the Month dropdown, select February. In the Year input, enter 2020.

  • Click Start. Review the results of the Chain on the Log tab of the Render Text Template - Create Period Key Command.

  • Execute the Chain again using February but enter 2021 for the Year for this execution. Confirm that the month ended on the correct day.

2020 Example

2021 Example


📚 Topics covered in this exercise:

Runtime Inputs
Handlebars

Variable Transformation


Did this answer your question?