 |
Online Help System
|
 |
Back to Brilliant Database Web-Site |
Write to Support |
Help Index
User Functions
Introduction
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 database software record specified values to specified fields of a selected database database software 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
- Name - specify the function name;
- Argument Name (1, 2, 3) - specify names of arguments where input variables will be database software recorded;
- Description (1, 2, 3) - argument description;
- Function returns value) - select this check box if you want the function to return its value. You can use the text box on the right to describe the value.
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 database software 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:
- In line 2 we call the ChangeQuantity user function and database software record its result to the [$new_total] variable.
- Line 3 shows the value of the [$new_total] variable.
Changing Many Records with User Function
This way of modifying database software records is obsolete. It is much more convenient to
modify database software record in cycles. Know more...
You can apply a User Function to several database software records (a set of database software records).
For example, you can change the value of database software record fields, e-mail a database software record, etc.
Let's take the ChangeQuantity User Function described above. To perform an action with a database software recordset, we should do the following:
- 1. Create a variable with a database software recordset using a query or a relational field. To learn more, see the RecordSet variables section.
- 2. Call our User Function for the current database software recordset using the
Run Script For Recordset action.
The script for changing several database software records looks like this:
See Also:
Script Designer
Using Variables
Action Editor
List of actions
Text Formulas
|