Field value changed hook example

Use Value-changed hooks to synchronize fields or perform other tasks after the value in a field has changed.

In the following example, the hook checks the name of the operating system stored in the current field. Depending on the operating system, the hook then assigns a version number to the OS_version field. If the current field has not yet been set, and thus does not contain the name of the operating system, this hook does not set the corresponding version number.

VBScript


Sub OS_type_ValueChanged(fieldname)

    ' fieldname As String

    value = GetFieldValue(fieldname).GetValue()


     If value = "solaris" Then

       SetFieldValue "OS_version", "7.x"

     ElseIf value = "windows" Then

       SetFieldValue "OS_version", "95"

     ElseIf value = "hpux" Then

       SetFieldValue "OS_version", "10.x"

     End If

End Sub 

Perl


sub OS_type_ValueChanged  {

    my($fieldname) = @_;

    my($value);

    $value = $entity->GetFieldValue($fieldname)->GetValue();


    if ($value eq "solaris")  {

      $entity->SetFieldValue("OS_version", "7.x");

    } elsif ($value eq "windows")  {

      $entity->SetFieldValue("OS_version", "95");

    } elsif ($value eq "hpux")  {

      $entity->SetFieldValue("OS_version",  "10.x");

    }

}