Valider

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.

Vous pouvez uniquement appeler cette méthode si l'objet Entity est éditable. Pour rendre un objet Entity existant éditable, appelez la méthode EditEntity de l'objet Session.

Remarque : 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. Pour plus d'informations, voir Contrôle des erreurs et contrôle de validité. The Exemple de crochet de validation d'action 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 ClearQuest clients. However, be aware that using this type of validation too often might slow performance.

Syntaxe

VBScript

entity.Validate 

Perl

$entity->Validate(); 
Identificateur
Description
entity
Objet Entity représentant un enregistrement de données utilisateur. Si vous omettez cette partie de la syntaxe au sein d'un point d'ancrage, l'objet Entity correspondant à l'enregistrement de données en cours est faux (VBScript uniquement).
Valeur renvoyée
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.

Exemples

VBScript

set sessionObj = GetSession 

set entityObj = sessionObj.GetEntity("defect", "BUGID00000042")
sessionObj.EditEntity entityObj, "modify"   

' modify the Entity object 


status = entityObj.Validate 

     if status = "" then

         entityObj.Commit 
      else

          entityObj.Revert  

       End If
' The Entity object is no longer editable 

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 

Feedback