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” - In Automate Desktop, 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 .
Scope and Accessibility
Scope and Accessibility provide two different capabilities to Automate Desktop 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.
Scope
Scope limits a task variable’s visibility within a task (that is, 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
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. Automate Desktop supports two levels of accessibility:
- 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 Task - Start subtask activity. In this situation, the parent task’s (that is, 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. This is fully backward compatible with previous versions of Automate Desktop, since in the past there was only one “function” (what is now called “main”), no task variables, and all (local) variables and extended functions were considered public.
Creating and Defining Task Variables
Task variables are scoped outside of task functions, and all task variables are accessible to all task functions in that task. They are created and presented in a separate panel located on the Steps panel.
To create and define a task variable
-
In the Task Builder's Steps panel, select Task Variables.
-
Click the Add Task Variable button. A panel opens where a new task variable can be added and specific parameters can be set.
-
Enter the following parameters:
Property Type Description Name Text The unique name of the task variable to create. Type Text (options) The type of task variable to create. The available options are:
- Variable - The return value will be in the form of a variable.
- Array - The return value will be in the form of an array.
- Dataset - The return value will be in the form of a dataset.
Access Type Text (options) The task variable's access type. The available options are: - Public - The variable is visible and accessible to external tasks.
- Private - The variable is not visible or accessible to external tasks.
Initial Value Text The initial value of the task variable (if any). Description Text An optional description of the task variable. -
When finished, click Save Changes. The newly created task variable along with its properties appears on the list of task variables available for the task.
Editing and Deleting Task Variables
To edit an existing task variable
- From the task variables panel, select the variable you wish to edit from the list and then click Edit.
- Make the desired modifications then click OK when finished.
- Reflected changes appear in the main panel.
To delete an existing task variable
- From the task variables panel, select the variable you wish to delete and click the Remove button.
- The task variable is permanently removed from the list of available task variables.