Previous Topic: Use Initialization ScriptsNext Topic: Use Field Event Scripts


Use Field Validation Scripts

The XML template can include form scripts that validate form data to help ensure that the user completes required fields and to alert the user when they do not. Scripted data validation occurs when a user saves a form in the Form Editor.

Follow these steps:

  1. Navigate to %AllUsersProfile%\Application Data\CA\SCM\Forms and use a text editor to open the XML file for the form in which you want to edit for validation.

    The form definition appears in the text editor.

  2. Define the field validation logic in the form definition within a validation block.

    Note: Your JavaScript must report validity by calling the editor.setValid method. Calling this method with false indicates that the form is invalid and thus saving should be disallowed.

    <validation language="javascript" client="eclipse">
       if (editor.getTextFieldValue("mrcategory").length() == 0)
       {
          editor.alert("You must select a category.");
          editor.setValid(false);
       }
    </validation>
    
  3. (Optional) Call an alert method to display an alert message in a pop-up dialog on the Workbench.

    For example:

    editor.alert("Form validation failed")
    
  4. Save the file and re-synchronize the form changes with your CA Harvest SCM server.

    Field validation is set.

More information:

How Forms Use JavaScript Scripts