Reusing Script Components

Many objects require the same processing steps in their scripts. By reusing scripts, you reduce design and maintenance efforts, and can help achieve consistent patterns. There are several ways that you can reuse scripts.

This page includes the following:

Reusing Values Within a Script

Use script variables when you need to reuse values within your scripts. The value can be a string, number or another variable, and you can optionally declare its data type.

More Information:

Example

In the following script, the script statement assigns a string as the value of a variable. That string is then passed to the activation report when the object is executed. The script also displays the string in a dialog box.

Syntax

:SET &HELLOMSG# = "Hello world."

:PRINT &HELLOMSG#

 

:BEGINREAD
:PRINT &HELLOMSG#
:ENDREAD

Parameters

Reusing Scripts With Include Statements

Use Include objects (JOBI) to store script blocks that you want to be able to insert into the Process pages of different objects. The advantage of using Include objects is that the reusable script is inserted directly into the object properties. By using :INCLUDE statements, you can reduce the number of separate objects in your workflows. This approach makes workflows easier to modify because the reusable scripts are integrated in the objects they affect.

More Information:

Example

Create an Include object that stores a script lines that retrieves the system time and stores it in a variable.

Write the lines of script that you want to be reusable on the Process page of SETTIME.JOBI. In this example, the reusable script sets a variable using the system time function:
:SET&VARTIME# = SYS_TIME()

You can now call this Include object whenever you want to provide the system time.

Follow these steps to include your reusable script block during runtime.

  1. Open the object where you want to include the reusable script block.
  2. Write an :INCLUDE statement in the Process page of the object to call the Include object that stores your reusable block:
    :INCLUDE SETTIME.JOBI
    The script lines from your Include object are inserted.
  3. Click the + icon to view the script lines.
  4. Save the object.
  5. Add the object as a task in a workflow.

When the task is processed in the workflow, the :INCLUDE statement calls the Include object and your stored script is processed during runtime.

Notes:

Tip: Make a folder to store a collection of reusable scripts for common processes to reduce your maintenance and design efforts.

Reusing Scripts Stored in Script Objects

Use Script objects (SCRI) to store scripts for internal processing when you want to be able to add them as separate objects in workflows. For example, you may have a set of internal instructions that should be processed after a number of parallel jobs in a workflow. In this scenario, it would not make sense to include the script in any one or all of the preceding tasks. For more information, see Scripts (SCRI).

Reusing Scripts Within an Object

Use the :INC_SCRIPT statement to call a script within another script in the same object.

Note: You can only use this statement in object types that have more than one Process page.

For more information, see :INC_SCRIPT.

Example

Follow these steps to call the complete script from one Process page on another Process page in the same object. In this example, a script statement on the Process page calls a script on the Pre-process page.

  1. Write a script on the Pre-process page of a job object.
  2. Write a script statement on the Process page of the object to call the script you wrote on the Pre-process page:
    :INC_SCRIPT (1)
  3. Save the Job.

When the job executes, the script is processed twice: first when the Pre-process page is processed, and again when the Process page is processed.

Importing and Exporting Script Lines

You can import and export lines of code in the script editor. Exporting code lets you reuse scripts across installations quickly and easily. This function is available on all Process pages as well as in the Script object.

For more information, see Importing and Exporting Code Chunks.

See also:

seealso

Functional Logic with Scripts

Writing Scripts

Script Elements Ordered by Purpose

Alphabetical List of Script Statements and Functions