Task Functions

You can organize and structure tasks with the use of task functions. In programming, functions allow the structuring of programs in segments of code to enable performance of individual tasks. A function normally performs a calculation and returns a value. The same holds true for task functions in the Task Builder. Each task function performs an operation and optionally returns a value.

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

Task Functions are additional features aimed for advanced users. You can build tasks without the use of Task Functions and may choose to use these features at your own pace.

Scope & Accessibility

The power of task functions comes from their ability to provide variable modularity and protection and their capability to arrange a collection of task steps into a logical structure. This is accomplished through two distinct yet complimentary standards; scope and accessibility. Scope and accessibility are primary building blocks used to construct a solid foundation and to enable a rich object-oriented approach to tasks. They provide distinct capabilities and serve different but complimentary roles necessary to distinguish the benefits of task functions.

Scope

A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable cannot be accessed. A scope limits a task function's visibility within a task. Without proper scoping, some of the primary advantages of function-oriented design would not be possible, 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. Scoping also helps avoid unintentional and confusing data changes leading to easier debugging as well as construction of 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. 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. Task functions exist at the root of a task structure, thus, their scope is to the entire task. However, their accessibility, which defines whether or not the function is accessible and visible to an external task, can be defined in the following manners:

  • Public - Visible and accessible to external tasks.

  • Private - Not visible or accessible to external tasks. Access is limited to the containing type.

The ability to set task functions as public or private give developers greater control over how a task is used by another task.

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 (i.e., the task executing the Start sub-task step) basic functions,extended functions, public task functions, public task variables, and any local variables (not marked 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 sub-task action 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, 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 Functions

When you define a task function, you can optionally define one or more named, typed values that the function receives as input (known as argument parameters). You can declare arguments as optional and set a default value for any argument - so if the argument is not present, the default value will be used. You can also define a type of value that the function will pass back to the task as output upon completion (known as return type).

Function argument parameters and return values are extremely flexible. You can define anything from a simple utility function with a single unnamed parameter to a complex function with expressive parameter names and different parameter options. You can provide default values to simplify function calls and can be passed as in-out parameters, which modify a passed variable once the function has completed its execution.

To create and define a new Task Function

  1. In the Task Builder's Steps panel, click the View function properties icon. The panel expands to display available function parameters.

  2. Enter the desired information in the Name, Type and Function parameters.

  3. To add an argument, click Add. The Argument dialog box appears.

  4. Enter the required information and then click OK.

  5. To add additional arguments for the current function, repeat steps 3-4.

  6. To edit or remove existing arguments for the current function, select it from the Parameters list and click Edit or Remove.

Function Parameters

The following table describes the parameters available during task function creation/modification.

Property

Type

Description

Name

Text

The identifier by which the function can be called. This parameter defaults to the name NewFunction but can be modified to a name that better identifies the function.

Return type

Text (options)

The return value type. The available options are:

  • Nothing - No value (nothing) will be returned.

  • 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.

Function is private

Yes/No

If set to YES, the function becomes private.

 

Argument Parameters

The following table describes the parameters available during task function creation/modification.

Property

Type

Description

Name

Text

The identifier by which the function can be called. This parameter defaults to the name NewFunction but can be modified to a name that better identifies the function.

Type

Text (options)

The return value type. The available options are:

  • Nothing - There will be no return value.

  • 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.

Optional

Yes/No

If set to YES (enabled), the argument will be optional. When you define a complicated function, you will often want to let the argument(s) of the function to be "optional" for flexibility.

Default value

Text

The function's default value (if any).

Calling Task Functions

A function doesn't do anything until it is called. Every function has a function name which may describe the procedure that the function performs. To use a function, you “call” that function with its name and pass it input values (known as arguments) that match the types of function’s parameters. If you are calling a function with no parameters, an empty pair parentheses is required.

The Call function activity calls a function defined in the task. If the function returns a result, you can specify the name of the variable in which to place the value. This activity is mainly used to pass control to a subroutine; after the subroutine is executed, control returns to the next instruction in main task.

In addition, the Return activity can be used to exit the current function and return task execution to the calling function. A return value can also be specified to the caller. This activity immediately ends execution of the current function and returns its argument as the value of the function call.

Task Events

A list of pre-configured task functions are included in the drop-down list of available functions. These objects contain default parameters, arguments and return values, therefore, they cannot be modified. Tasks become more robust when task events are implemented. This is because events make a task more intelligent with their ability to monitor execution status and provide notification when a status has changed. You use them similar to a task function you created.