Task Variables

Task variables provide a means of sharing common data within a single function or between more than one function. The parameters of a task variable are similar to that of a task function which comprise a Name, Type and Accessibility descriptor. In addition, a task variable also includes a Description parameter as a way to distinguish each variable. Unlike a task function, however, a task variable cannot be marked as Optional. Some advantages of task variables are as follows:

  • Preservation of task-centric values - Data that is common to an entire task or used by one or more functions are candidates for elevation to a task variable. An example could be a variable to indicate whether the task is in “normal” or “error recovery” mode.  

  • Can be used as a “named constant” - A constant is defined at the system level. However, there are situations where a value is meant to be preserved throughout the lifetime of a task, regardless of function or external task, but not dictated by the system configuration. A task variable can accomplish this, optionally with the read-only option set.

  • Allows information-protection and controls access by external tasks - This can be accomplished by using the Accessibility preference of a task variable. They control which task variables are merged into a parent task or accessible through a task object.

Task variables, functions and events are created and managed through a drop-down UI display that is accessible from the Steps panel of Task Builder (as shown below).

Task Variables are different from Local Variables that are created using the Create variable activity. In addition, Task Variables are additional features aimed for advanced users. You can build tasks without the use of Task Variables and may choose to use them at your own pace.

Scope and Accessibility provide two different capabilities and serve two different but complimentary roles necessary to realize the full benefits of task variables. They are primary building blocks that can be used to build a solid foundation for a rich object-oriented approach to tasks.

Task variables are scoped outside of task functions, and all task variables are accessible to all task functions in that task.

Scope limits a task variable’s visibility within a task (e.g., using a variable from “the inside”). Without proper scoping, it would not be possible to provide some of the best advantages to function-oriented design, including information-protection, modularity, maintainability and recursion. Scoping helps take large, unruly tasks and enforce logical restrictions to their structure to provide greater readability and maintainability. They can help optimize and enhance task execution speed by reducing the amount of variables that are present in the system at a given time. Scoping also helps avoid unintentional and confusing data changes and variables accesses, leading to easier debugging, and cleaner and more reliable tasks.

Accessibility provides the fundamentals of information-protection, encapsulation and interfacing, all of which are essential for an object-oriented approach to a language. The ability to set task variables and functions as public or private gives a task developer greater control over how a task is used by another task. It makes tasks more portable, manageable and documentable by providing outside access only to those parts of the task that are meant to be used, while providing the user full flexibility of functions. Two levels of accessibility are supported:

  • Public - The variable or function is visible and accessible to external tasks.
  • Private - The variable or function is not visible or accessible to external tasks.

The accessibility of a task variable can be adjusted to suit the information-protection needs of the task as it relates to an external or sub-task. By default, a task variable is public, meaning it is accessible to an external task or external task function. This is accomplished in different ways, depending on how the external task is referenced, but the behavior of the task variable is identical regardless.

Sub-Tasks

Sub-tasks are task files that are executed within another task by using the Start sub-task activity. In this situation, the parent task’s (e.g., the task executing the Start sub-task step) basic functions, extended functions, public task functions, public task variables, and any local variables (unmarked as private), created up to point where the Start sub-task step is encountered, are accessible to the sub-task. All other variables and functions are not accessible to the sub-task. Conversely, because the Start Task activity is a synchronous operation, the sub-task’s public functions and public task variables are not accessible from the parent task.