Ejemplo de enganche de validación de acción

Los enganches de validación de acción comprueban condiciones que son difíciles de verificar a nivel de campo como, por ejemplo, si un conjunto de valores de campo relacionados es válido. Los enganches de validación a nivel de campo se ejecutan inmediatamente después de modificar el campo; los enganches de validación de acción no se ejecutan hasta que el usuario ha terminado de modificar el registro y está preparado para confirmarlo en la base de datos.

En el ejemplo siguiente se comprueba que el usuario entra un valor de sistema operativo (OS) de cliente correcto para el proyecto dado. Si el sistema operativo especificado para el proyecto no está soportado, el enganche genera y devuelve un mensaje de error de validación.

VBScript

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 

Perl

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. Si el

    #  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;

} 

Comentarios