Dynamic Variables

Dynamic variables are a way to make a workflow more dynamic in terms of the content that is shown based on the current execution of a workflow. It could be as simple as showing an answer from a previous step for reference in a later such as the image below, Or it could be used to show completely different content including data results from a collection (see collections). 

This should enable the workflow designer to ensure that workflows are created in a way that takes full advantage of the fact that they are in a digital form and are not paper. 


How Does it Work?

There are two key components that allow Dynamic Variables to work.

  1. Handlebars - this is the language and notation that is used to let the workflow know it should be doing something special here and not just display normal text.

  1. The Instance Data - As a user is completing a workflow the system is hoovering up every piece of information it can, when the steps were completed, what the answers were etc. Not only is this information always stored and recorded but it can be used by the dynamic variables. 


It is the combination of understanding the data that is available and how to take advantage of handlebars to decide what and how we choose to display that data. Handlebars is an extensible language, and as such, we have made some additional helpers which will also be covered below. Handlebars also have great documentation on how to use it and get started here: https://handlebarsjs.com/guide/

The Data

 Below is what the data looks like that is available to you as a user:

JobId

Team

CompletedSteps

  • SingleStep

    • StepId

    • StepTitle

    • StepDescription

    • UserId

    • UserName

    • StepNumber

    • StepType

    • Started

    • Completed

    • Updated

    • Cancelled

    • TimeEvents

      • Key

      • TimeEvent

    • Note

    • Metadata

      • Key

      • Value

    • Value

    • Values

    • ValueResourceIds

  • ReportStep

    • StepId

    • StepTitle

    • StepDescription

    • UserId

    • UserName

    • StepNumber

    • StepType

    • Started

    • Completed

    • Updated

    • Cancelled

    • TimeEvents

      • Key

      • TimeEvent

    • Note

    • Metadata

      • Key

      • Value

    • Steps

      • StepId

      • ValueResourceIds

      • Values

      • Value

      • StepTitle

      • StepDescription

      • StepType

    • LoopIteration

CancelledSteps

  • SAME AS COMPLETED STEP

Metadata

  • JobTitle

  • Created

  • Updated

  • CurrentStep

    • SAME AS COMPLETED STEP

  • Shedule

    • SheduleId

    • Start

  • UserId

  • UserName

  • Status

  • AbandonReason

  • Metadata

    • Key

    • Value


Functions
Handlebars is a useful language to used to display content. But if you want to do more complex things; then you need to add your own functions to it. Here are some of the things we have found useful for ourselves and thought we would share with everyone. Below are a list of the functions we have created, and we can tell you what they are for and how to use them: 


General Functions

getDateTime

This is used to format a date to the style you required for example:

10th of July 2020

2020/07/10 14:21

6pm on Saturday the 15/01/2020

Arguments:

1. A date time value
2. The format of the data using c#'s date time library. (More info: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings)


Example:

{{getDateTime this.metadata.created "dd-mm-yyyy"}}


matchRegex

This will use a regular expression to find a value in the provided string and print it out. For example if I had a step referencing a serial number: 

123-12345-AB

And the only important bit to my was the characters at the end then I would use the matchRegex function to extract this.

Arguments:

1. The string to do the searching in. 
2. The regular experession to perform 
3. The casing to be used on the result. Values can be:

        a. Title 
        b. Lower
        c. Upper


Example:

{{matchRegex "AASD-LAND-FORCE' '/[^;]*/" "LOWER'}} 

Would return: aasd



ifCond

This can be used to conditionally show or perform further logic.

Note: the expression will only work with strings, integers and floats currently.

Arguments:

1. Left side of operation
2. Operator
        a. >
        b. =
        c. ==
        d. <
        e. !=
        f. <>
3. Right side of operation


Example:

{{#ifCond this.SingleStep "==+ an "Checklist"}}

This text will only display if this step happens to be a checklist step
{{/ifCond}}


ifNullOrEmpty


This can be used to check if there is a value in a field.


Arguments:

1. Value to check
2. If you want to reverse the condition use the ! symbol here. 


Example:

{{#ifNullOrEmpty this.SingleStepDescription}}

This text will only display if this StepDescription variable is not empty
{{/ifCond}}


getStepByTag


This can be used to return the Step object by searching for its tag. It will look for the most recent completion of it and then return it for use.


Arguments:

1. Tag Name 


Examples:

Examples

{{#getStepByTag "MeterReading"}}

    The {{this}} context has now been updated to read from the step that has been found So the value of the step with the tag "MeterReading" is: {{this.SingleStep.Value}} {{/getStepByTag}}



ifstepArrayHasNotes


This can be used to check whether the step object contains any notes. 


Arguments:

    1. Array of steps
    2. Not ("!") [optional] - Reverses the condition to check that there are no steps with notes instead.


Examples:

{{#ifStepArrayHasNotes CompletedSteps}}

This text will show if one or more of the completed steps contain notes.
{{/ifStepArrayHasNotes}}{{#ifStepArrayHasNotes CompletedSteps "!"}}
     This text will show if none of the completed steps contain notes
{{/ifStepArrayHasNotes}}


Useful Snippets

Display the current state of The Data

We have found this below snipped really useful. It will loop through all the data that is available and print it out on the screen. This can be really useful when debugging or trying to understand what you are working on.



handlebars

*Top Level*

{{#each this}}

{{@key}} 

{{this}}

---

{{/each}}


*Completed Steps*

{{#each CompletedSteps}}

Step {{@key}}

{{#each this}}

{{#each this}}

{{@key}}

{{this}}

---

{{/each}}


VALUES

{{#each Values}}

{{@key}}

{{this}}

---

{{/each}}


METADATA

{{#each Metadata}}

{{@key}}

{{this}}

---

{{/each}}


--- Step Type End


{{/each}}          

{{/each}}





A
Alana is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.