Gli hook di convalida azione esaminano condizioni difficili da verificare a livello di campo come, ad esempio, la validità di una una serie di valori campo correlati. Gli hook di convalida a livello di campo vengono eseguiti immediatamente dopo la modifica del campo; gli hook di convalida azione non vengono eseguiti fino a quando l'utente non ha terminato di modificare il record ed è pronto ad eseguirne il commit sul database.
L'esempio che segue verifica che l'utente immetta un valore SO (sistema operativo) client corretto per il progetto specifico. Se il sistema operativo specificato per il progetto non è supportato, questo hook genera e restituisce un messaggio di errore di convalida.
Function defect_Validation(actionname, actiontype)
' actionname As String
' actiontype As Long
' defect_Validation As String
' action = teststate
set sessionObj = GetSession
' Get the client OS platform the user indicated.
platform = GetFieldValue("client_os").GetValue()
' Get the project name the user indicated. This information
' is stored on a referenced, stateless record.
projectName = GetFieldValue("project.name").GetValue()
' Check the project name against the OS type. If the given project
' is not targeted for that platform, return a validation error.
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 as string scalar
# $actiontype as long scalar
# $result as string scalar
# action = teststate
# Returns a non-empty string explaining why the action
# can not commit with the current values.
# Or, if it is valid, returns an empty string value.
my ($session,
$platform,
$projectRecordID,
$projectRecord,
$projectName,
);
$session=$entity->GetSession();
# Get the client OS indicated by the user.
$platform = $entity->GetFieldValue("client_os")->GetValue();
# Get the project name the user indicated. This information
# is stored on a referenced, stateless record.
$projectName = $entity->GetFieldValue("project.name")->GetValue();
# Check the project name against the OS type. If the
# 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;
}