Add a field hook

In this exercise, you will create a hook script and add it to the User_ID field that you previously added to the Defect record type. When you added the User_ID field, you defined its field type as Integer because users will enter a number in the field. Now you want to validate that users enter a number between 1 and 100.

To add a field hook:

  1. In the Designer workspace, expand the Record Types folder and the Defect folder.
  2. To open the Fields grid, double-click Fields.
  3. Click the Validation column cell for the User_ID field row; click the down arrow; and select SCRIPTS > BASIC. At the top of the Script editor, the Fields option is set to User_ID and the Hook Types option is set to FIELD_VALIDATION.
  4. Enter the following code directly below the line that reads REM End IF:
    Dim value_info
    Set value_info = GetFieldValue (fieldname)
    If Not IsNumeric(value_info.GetValue) Then
    user_number_Validation = "Must be an integer between 1 and 100"
    ElseIf (value_info.GetValue < 1) or
    (value_info.GetValue > 100) Then
    user_number_Validation = "Must be between 1 and 100"
    End if

    When a user enters a number in the User_ID field, the Rational® ClearQuest® client runs this validation hook script. If the user enters a nonnumeric value, or a number that is not in the range of 1 and 100, the hook script displays the appropriate error message.

  5. Click Hooks > Compile to compile the script. The script should compile without error.
  6. Close the Script editor.