Validate

Description

Validates the Entity object and reports any errors.

Before an Entity can be committed, it must be validated (even if no fields have been changed). If you are changing the contents of a record programmatically, you should make sure that your code provides valid data.

You should not attempt to parse and interpret the returned String programmatically, because the error text may change in future releases. If you want to try to correct the value in an field with incorrect values, you can use the GetInvalidFieldValues method to get the FieldInfo Object for that field.

You can call this method only if the Entity object is editable. To make an existing Entity object editable, call the EditEntity method of the Session object.

Note: On failure, the method might return a string containing an error message or an exception, depending on what causes the failure. For example, the method returns a string containing an error message for failures such as invalid values set for fields. However, the method throws an exception for other failures, such as trying to change an entity that is not in an editable state. Your code should handle both types of potential failures. See Error checking and validation for more information. The Action commit hook example provides examples of error and exception handling when calling the Validate and Commit methods.

You can also call this method from within any hook to refresh the validation data that is available to the DevOps Plan clients. However, be aware that using this type of validation too often might slow performance.

Syntax

Perl


$entity->Validate(); 
Identifier
Description
entity
An Entity object representing a user data record. Inside a hook, if you omit this part of the syntax, the Entity object corresponding to the current data record is assumed.
Return value
If the Entity object is valid, this method returns the empty String (''). If any validation errors are detected, the String contains an explanation of the problem, suitable for presenting to the user.

Example

Perl


# Get the current session

$sessionobj = $entity->GetSession();

# Select an entity to modify

$entityobj = $session->GetEntity("defect","BUGID00000042");


# Take the modify action on the entity object

$sessionobj->EditEntity($entityobj,"modify");

# ...make modifications to the entity object


$status = $entityobj->Validate();

   if ($status == ""){

      $entityobj->Commit();

      }

   else {

         $entityobj->Revert();

      }

# At this point, the entity object is no longer modifiable