Create a User-Defined Function

About this task

This topic describes how to create your own function to use in a calculation formula. For more information, refer to User-defined Functions. You can also use any of the built-in functions.

Before you begin

Create the tag that you want to use to store the calculation results. You can create the tag manually using Configuration Hub, Historian Administrator or the Web Admin console. Or, you can copy a tag.

Procedure

  1. To create a user-defined function using Configuration Hub:
    1. Access Configuration Hub.
    2. In the NAVIGATION section, under the Configuration Hub plugin for Historian, select Tags.
      A list of tags appears.
    3. Select a calculation tag, right-click or select more options, and then select Calculation.
      The calculation editor appears.
    4. In the CALCULATION section, remove Null (retain Result =).
    5. In the calculation editor, place the cursor in the location where you want to insert the user-defined function.
    6. In the DETAILS section, under User Defined Functions, select .
      The Add/Edit User Defined Functions (UDF) window appears.
    7. Select Add New.
      A function is created with the following naming convention: UserFunction<number>. The same function is used in the function editor. You can change the function name by entering the new name in the function editor and selecting Update UDF.
    8. Enter the VB script for the function. Or, if you want to use a pre-built function, select the function type and function in the respective fields under Pre-Built Functions. And, enter values in the other fields that appear after selecting a function.
      The function appears in the function preview below the function editor.
    9. Select Insert Preview.
      The function is included in the function editor at the cursor position.
    10. To test the function syntax, select .
      A message appears, stating whether the function syntax is correct.
    11. Select Update UDF.
      The user-defined function is created.
    12. To use the function in the calculation formula, select Insert UDF.
      The function is inserted in the calculation formula at the cursor position.
    13. To test the calculation formula, select .
      A message appears, stating whether the syntax is correct.
    14. In the upper-left corner of the page, select Save.
      The calculation formula is created.
  2. To create a user-defined function using Historian Administrator:
    1. In Historian Administrator, select Tags, select the tag for which you want to create a calculation formula, and then select Calculation.
    2. In the Calculation section, remove Null (retain Result =).
      Tip: Avoid selecting other tags until you save your changes or you will lose your code changes.
    3. Select Functions.
      The User Defined Functions window appears.
    4. Select New.
      The Edit Function window appears.
    5. Define the function.
      You can build formulas using the wizard, or create it manually by entering functions in the Edit Function box. For information, refer to User-defined Functions.
    6. Select Syntax to check for errors.
    7. Select Update.
      Your function appears in the list, and is available for use in other calculations as well.
    8. To use the function, select Insert Function.
      The function is inserted in your calculation formula.