Tutorial 21 - User Functions

User Functions utilize the same format as Transactions, Subledger, and Global Procedures; however, they do not contain any Field-based resources (under the Local area of Main Resources) since they are not related to any specific Template. When saved, User Functions are encapsulated executable Procedures that can be included in other Procedures

Exercise 21 - 1, Expiry Date for Credit Cards
In Tutorial 22, you will encounter a Subledger Procedure with a Date input field for the Expiry Date of a Credit Card. Credit Card companies specify their expiry date with an MM/YY format where the day is always the end of the month. When entering a date in STEP FORWARD in the MM/YY or MMYY format it will be recorded internally as YYYYMM01 (the first day of the specified Month/Year combination). The User Function which you are about to create will allow you to type the date in the MM/YY or MMYY format and convert the internal format from YYYYMM01 to YYYYMMDD where DD is the last day of the specified month.

1. Launch Date Formats editor, select the Formats > Add menu item and add the MM/YY and MMYY formats if not already present.
Select the Formats > Save menu item followed by Formats > Quit.
2. Launch the User Functions editor.
Select the Preferences menu item and select the Date formats option.
Select the MM/YY and MMYY as the only options and position them as per example:
This will allow you to enter in the month/year as either format but display it as the MM/YY format used by the banks.

3. Complete the function as per the example:
Select the Parameters box and set Date as the Type;
click-select or drag-drop New parameter from the Palette (Local) into the Parameter's editable field;
and rename par1 by double-clicking par1 in the Palette and typing Expires.

Drag a Function object from the Palette and position it below the Parameters box.
This will display the Functions view of the Palette.
Select the AddToDate function from the System section by double-clicking or drag-dropping.

Click-select the Expires from the Parameters section of the Palette.
This will fill in the Date field of the Function object.
Click on the run-time switch of the Increment field, making it editable and type 1.
Click on the run-time switch of the Units field, presenting you with a pop-up list; select Months.

Click-select or drag-drop New variable from the Palette (Local) into the Return value field of the Function object;
and rename var1 by double-clicking var1 in the Palette and typing New Date.

Drag a Calculation object from the Palette and place it below the Function object.
Click-select or drag drop New variable from the Palette.
Click-select or drag drop = from the Palette, or type a space followed by = and a space (spaces are purely cosmetic in this case, they are not mandatory in calculations).
Click-select or drag drop New Date from the Palette's Variables, or type [New Date].
Type a space followed by -1;.
Click on the Workspace background to disable the Calculation object.
Rename var 1 in the Palette to Expires end of.
Resize the Calculation object to suit.

Select the Return value object.
Click-select or drag drop Expires end of from the Palette's Variables.
Connect the objects and Save as ExpiresMonthEnd.

4. Test the Function by entering 0900 into the Expires end of: Parameter field and Step (button) through the Procedure. You will note that:
the typed date 0900 is re-displayed as 09/00 in the Parameter's field;
the Input parameter 0900 is converted to 20000901 or September 1, 2000;
the Function AddToDate increments the date by one month to 20001001;
and the Calculation subtracts 1 day giving us the Function return value of 20000930 or September 30, 2000.

Exercise 21 - 2, Generic Description for AR and AP Templates
The AR and AP Templates which were created as part of Tutorial 19 had their Cursor movement established in such a manner that it moves from GL -> Description -> Subledger. This enables you to enter the name of the Customer or Vendor in the Description field for the purpose of retrieving the applicable Subledger number. However, on saving the completed Document we want to replace the Customer/Vendor names in the Description field with something generic such as Invoice, Credit Note, and Payment Received. The applicability of one of these three terms can be determined by examining the Source Document name and the sign (+ or -) of the Amount - this Function will do that.

In Tutorial 25, you will be using this Function as part of the Saving record Procedure for the AR and AP Templates. As you configure this Function, please note that "Source" and "Amount" are Parameters, and "Doc" is a Variable (both are user-defined in the Palette). On completion Save with the name DocText.

Go To
  Tutorial 22 - Subledger Procedures