User Function is a script that can be executed from other scripts. For example, if you use a set of actions in several scripts, you can create a User Function containing these actions and call this function when you need.
User Functions can accept arguments and return the result of their work to a specified variable.
For example, you can create a User Function that calculates a complicated formula basing on some input data and returns the result to a variable. You can also record specified values to specified fields of a selected database record.
Using User Functions
Here is an example of simplifying the script described in Script Designer using a User Function:
First the script asks the user to enter the value of the [$quantity] variable that should exceed 0, then it increases the value of the [Order Total] field of the current folder by the entered value.
Let's replace this part of the script with a User Function:
Creating a New User Function
To create a new User Function, click User Functions > Create New... or right-click the User Functions tree and select Create New...:
Enter the name of the new User Function. For example, ChangeQuantity.
Click Ok to open the User Functions editor:
Editing User Functions
Editing a script in User Functions is similar to editing an ordinary script. See the Script Designer section for more information.
As noted above, a User Function can accept arguments and return values to a variable. To set a User Function, click the UF Setup... button or click User Function Properties... in the menu:
User Function Properties
If you change the User Function properties as shown on the illustration, predefined variables will appear in the script tree of the UF editor:
You should record the result of the User Function to the [$result] variable at the end of the script.
We'll create a User Function using these variables:
Click Ok to save the User Function.
Inserting a User Function to a script
To call a User Function from a script, click User Functions > Insert... or double-click the required function in the function tree.
A standard Select Action dialog box will open:
In the dialog box we can set values of the User Function (default, text) and specify the variable where the action result will be saved ([$new_total]).
Thus, the script containing a User Function will look like this:
Copyright (C) 2001-2010 Binary Brilliant Inc. All Rights Reserved.