Follow email Print print

Calculations and Variables

NEW FUNCTIONALITY - COMING SOON!

CONTENTS

What are calculations and variables?

How to create a variable

How to write a calculation rule

Text variables and piping

Numeric variables and set values

Numeric variables and dynamic tasks


What are calculations and variables?

Calculations are a type of advanced logic rule that define the value of a variable. Variables can be text-based or numeric. 

Text variables can be: 

  • A specific string value or fact
  • A derived value that combines data from multiple fields

Numeric variables can be:

  • A specific integer value or fact
  • A computed value calculated by an arithmetic operator (+, - , / , %) 

Calculations can be used in multiple advanced logic rule types. Some examples of when to use a calculation include:

  • set value rules that compute and insert a variable’s value as a task response
  • dynamic tasks that are shown or hidden based on the value of a variable
  • piping expressions that dynamically insert the value of a variable into Mission fields 

How to create a variable

To create a variable:

  1. Navigate to the mission builder logic tab and select Add Variable on the variables panel:
  2. Define whether your variable will be text or numeric. Text variables contain words or strings. Numeric variables contain integers.
  3. Name your variable in the variable text box. Variable naming conventions must be unique and cannot match any other GoSpotCheck object name or task identifier name. If your name matches a reserved word, an error will appear:
  4. Variables with unique names will automatically save and can be referenced in advanced logic rules. Tip: leverage underscores to ensure variable naming conventions are considered unique. 

How to write a calculation rule

Text variables and piping

There are numerous ways a text variable can be piped into supported Mission fields (instructions, titles, descriptions). 

As an example, you can set a value for a text variable that can be used in mission instructions: 

  1. Determine the condition on which the rule should be run. A condition is provided with an IF, IF NOT, or IF ALWAYS statement at the beginning of a rule. IF ALWAYS will always set the value of a variable as defined in the logic statement. To set the value for a text variable, use THEN SET VALUE as the rule’s action expression. Incomplete rules are highlighted in red until complete: 
  2. Establish the string value for the text variable. The word TO will precede the quoted string value. In this example, the text variable mission_instructions is being given a value of ‘Hello. Please complete the following mission once per month’. This rule is still considered incomplete until it includes an event condition.
  3. Provide an event trigger for the rule. The four supported event types are 'ON RESPONSE', 'ON MISSION' or 'ON START', and 'ON MISSION AND RESPONSE'. ON RESPONSE will run the rule as the mission response is being completed, updating based on incoming task responses. 'ON MISSION' or 'ON START' will run the rule at the start of the Mission and will not update as the response is being completed. ON MISSION AND RESPONSE will run the rule in both scenarios. Given that our example will be used as mission instructions, an ON MISSION/ON START event type will ensure the instructions are present at Mission start.
  4. Leverage the variable in a way that logically adds value to a Mission. In this example, the variable can be piped into the mission instructions field between curly brackets. This will dynamically insert the defined text value into the Mission instructions.

Numeric variables and set values

Numeric variables can be used to run calculations on task responses and can also be inserted as task responses. 

To set a value for a numeric variable and use this value as a task response:

  1. Determine the condition on which the rule should be run. A condition is provided with an IF, IF NOT, or IF ALWAYS statement at the beginning of a rule. IF ALWAYS will always set the value of a variable as defined in the logic statement. To set the value for a numeric variable, use THEN SET VALUE as the rule’s action expression. Incomplete rules are highlighted in red until complete: 
  2. Establish a specific value or a calculated value for the numeric variable. In this example, total_fruit_count will sum two task response values, T1 (How many oranges are in the bin?) and T2 (How many apples are in the bin?). This rule is still considered incomplete until it includes an event condition.
  3. Provide an event trigger for the rule. The four supported event types are 'ON RESPONSE', 'ON MISSION' or 'ON START', and 'ON MISSION AND RESPONSE'. ON RESPONSE will run the rule as the mission response is being completed, updating based on incoming task responses. 'ON MISSION' or 'ON START' will run the rule at the start of the Mission and will not update as the response is being completed. ON MISSION AND RESPONSE will run the rule in both scenarios. Given that our example sums two task response values, an ON RESPONSE event type will ensure the rule is run as responses are submitted to the tasks referenced in the rule.
  4. Leverage the variable as a task response by defining which task should have the numeric variable dynamically populate as an answer. In this example, T3 (Total Fruit Count) will automatically be given total_fruit_count as a task response, meaning the task will be populated with the sum of T1 and T2. 

Numeric variables and dynamic tasks

To show or hide a task based on the value of a numeric variable: 

  1. Create a calculation rule for the numeric variable. In this example, the numeric variable is named total_fruit_count and its value is the sum of T1 (How many oranges are in the bin?) and T2 (How many apples are in the bin?).

Establish a rule that will show or hide a task based on the calculated value for a numeric variable. In this example, T3 (Answer if count is greater than 50) should be hidden if total_fruit_count is less than 50.

  

star
Have more questions? Submit a request