• Contents

Introduction to Subroutines

Subroutines are handlers started by other handlers, as opposed to handlers started by events on the CIC server. Subroutines are useful for many reasons.

First, a subroutine nicely encapsulates a set of logic into a single callable action. Thus, you can "reuse" a subroutine by calling it from any handler where that set of logic is appropriate. For instance, suppose that you have created a subroutine called LookupAccountNumber. Given a person's name, that subroutine will open a customer database, look up that person's account number and return the account number to the handler that called it. Now, imagine a system of handlers that deals with customer support. In such a system, the need to retrieve customer account numbers is a common one. Thus, when you build the customer support system, you would be able to call LookupAccountNumber from any handler that needs such information.

Second, subroutines ease your maintenance burden. Recall the first example of LookupAccountNumber. Suppose that, after your customer support handlers are finished and working, the customer database is redesigned. Instead of directly tying customer name to account number, the database has been changed to tie customer name to social security number, and then, in a separate table, to tie social security number to account number. Since your LookupAccountNumber localizes the access to the database in a single handler, you only need to change how LookupAccountNumber gets the information. Essentially, you'll change it to use the given name, retrieve a social security number, and then use the social security number to retrieve the account number. This change can be made without any changes to all the other handlers that call LookupAccountNumber.

Third, subroutines make handler building more visually manageable and understandable. By localizing groups of steps into subroutines, you can cut down on the number of steps that appear in the calling handler. Handlers with hundreds of steps can be very hard to understand and manage; a few subroutines can make a large handler easy to modify and understand. Essentially, by using subroutines properly, you break the logic down into manageable pieces.

How do I create a subroutine?

Creating subroutines is almost exactly like creating handlers. There are two differences.

The first difference is that every subroutine starts with a subroutine initiator. In this subroutine initiator, you'll define what information is passed into the subroutine from a handler that calls it. You'll also decide what information can be passed back to the handler that calls the subroutine. These pieces of information exchanged between a subroutine and its caller are called parameters. See Add or edit a subroutine parameter for more information.

The second difference appears during the publish process. If you are publishing a subroutine, you need to select or enter a subroutine category on the Publish Handler dialog. During the publish process, Interaction Designer creates a subroutine tool for the design palette.

How do I call a subroutine?

When a subroutine is published, a tool for that subroutine appears on the subroutine palette. To create a call to the subroutine from any handler, simply drag the subroutine tool from the subroutine palette and drop it onto the handler.

Loading and Viewing Subroutines

Subroutines may be saved and loaded into Interaction Designer in the same manner as other handlers. To ease handler authoring, however, there are two additional ways in which subroutines may be loaded and viewed:

  1. When viewing a handler containing a subroutine step, you may right-click on that step and select "Download from Server" from the pop-up menu. This will download the subroutine to the directory specified in the Designer Preferences. If no directory is specified there, the user will be prompted for one. Once the subroutine is downloaded, it will open in a new window.

  2. From the Subroutine page of the Design Palette, you can right-click on a subroutine icon and select "Download from Server" from the pop-up menu. This will also download the subroutine to a specified directory and open it in a new window.

The Published version of the subroutine that is running on the server will always be the version that is downloaded.

Related Topics

Add or edit a subroutine parameter