Crystal Reports  

Creating Custom Functions

When creating a new custom function, you can enter its logic directly in the Custom Function Editor, or you can extract the logic from an existing report formula.

Using the Custom Function Editor

  1. In the Formula Workshop, click New and select Custom Function from the list.
  2. Enter a name for your custom function in the Custom Function Name dialog box.
  3. Click Use Editor.
  4. Define your custom function in the Custom Function Editor.

    Using the Custom Function Editor is like using the Formula Editor to create a report formula. For information on how to use the Formula Editor, see the Formula Editor. For more information on what syntax to use when writing a custom function, see Basic Syntax for Custom Functions or Crystal Syntax for Custom Functions.

    Tip   Ctrl+Space brings up a list of the available functions. If you've already started typing, it brings up a list of keywords that are possible matches for what you've already typed.
  5. Check and save your custom function.

Once the custom function has been saved, you can modify it or use it in report formulas as needed.

Using the Extract Custom Function from Formula Dialog Box

When you extract a custom function from an existing formula, the program copies the formula and replaces its fields with arguments.

Note   A custom function created using the Extractor can return only simple types, like strings and integers. It cannot return arrays. To create a custom function that can return arrays, use the Custom Function Editor. For more information on return types and the syntax rules associated with custom functions, see Basic Syntax for Custom Functions or Crystal Syntax for Custom Functions.

To extract a custom function from an existing formula

  1. In the Formula Workshop, click New and select Custom Function from the list.
  2. Enter a name for your custom function in the Custom Function Name dialog box.
  3. Click Use Extractor.
  4. In the Formula list, select the report formula whose logic you want to use in your custom function.

    Once you've selected a formula, the Return Type, Arguments, and Formula Text fields are completed with information that relates to that formula. These fields cannot be changed without selecting a different formula.

    The remaining fields are optional. See Extract Custom Function from Formula dialog box for a description of each.

    Tip

    • You will probably want to create meaningful names for the arguments in your custom function. The program assigns generic names (v1, v2, v3, and so on) by default.
    • Select "Modify formula to use new custom function" to replace the text of the formula you selected in this step with the new custom function you're creating.
  5. Click OK to save the custom function to the Report Custom Functions node of the Formula Workshop.

Once the custom function has been extracted and saved, you can modify it or use it in report formulas as needed.

Note   You cannot add new arguments to your custom function while you are creating it in the Extract Custom Function from Formula dialog box. To add new arguments, save the custom function and modify it in the Custom Function Editor.

See Also

Basic Syntax for Custom Functions | Crystal Syntax for Custom Functions | Advantages of Using Custom Functions | Custom Functions Work Flow | Custom Functions