Action validation hooks check conditions that are difficult to verify at the field level, such as whether a set of related field values is valid. Field-level validation hooks run immediately after the field is modified; action validation hooks do not run until the user is finished modifying the record and is ready to commit it to the database.
The following example verifies that the user enters a correct client operating system (OS) value for the given project. If the operating system specified for the project is not supported, this hook generates and returns a validation error message.
Function defect_Validation(actionname, actiontype)
' actionname As String
' actiontype As Long
' defect_Validation As String
' action = teststate
set sessionObj = GetSession
' Obtenir la plateforme OS client indiquée par l'utilisateur
platform = GetFieldValue("client_os").GetValue()
' Obtenir le nom du projet indiqué par l'utilisateur. Cette information
' se trouve dans un enregistrement référencé sans état.
projectName = GetFieldValue("project.name").GetValue()
' Comparer le nom du projet et le type de système d'exploitation. Si
' le projet
n'est pas prévu pour cette plateforme, renvoyer une erreur de
' validation.
If projectName = "Gemini" Then
If platform <> "NT" Then
defect_Validation = "That project only supports NT."
End If
ElseIf projectName = "Aquarius" Then
If platform <> "Unix" Then
defect_Validation = "That project only supports Unix."
End If
End If
End Function
sub defect_Validation {
my($actionname, $actiontype) = @_;
my $result;
# $actionname : scalaire de chaîne
# $actiontype : scalaire long
# $result as string scalar
# action = teststate
# Renvoyer une chaîne non vide expliquant pourquoi l'action
# ne peut pas être validée avec les valeurs actuelles.
# Ou, si l'action est valide, renvoyer une valeur de chaîne vide.
my ($session,
$platform,
$projectRecordID,
$projectRecord,
$projectName,
);
$session=$entity->GetSession();
# Obtenir le système d'exploitation client indiqué par l'utilisateur.
$platform = $entity->GetFieldValue("client_os")->GetValue();
# Obtenir le nom du projet indiqué par l'utilisateur. Cette information
# se trouve dans un enregistrement référencé sans état.
$projectName = $entity->GetFieldValue("project.name")->GetValue();
# Comparer le nom du projet et le type de système d'exploitation. Si le projet
# given project is not targeted for that platform,
# return a validation error.
if ($projectName eq "Gemini") {
if ($platform != "NT") {
$result = "That project only supports NT.";
}
} elsif ($projectName eq "Aquarius") {
if ($platform != "Unix"){
$result = "That project only supports Unix.";
}
}
return $result;
}