Initialization hooks perform complex initialization at the beginning of an action. For example, you can use this hook to reset fields or to assign different values to fields based on the type of action.
The following code is a hook that runs when a user attempts to reassign a defect to another user. The hook clears the contents of the action_reason field at the beginning of a reassign action. If the behavior of this field is set to Mandatory, the user must provide a reason for reassigning the defect.
Sub swbug_Initialization(actionname, actiontype)
' actionname As String
' actiontype As Long
' action = reassign
' Empty the string at the beginning of the action
SetFieldValue "action_reason", ""
End Sub
sub swsub_Initialization {
my($actionname, $actiontype) = @_;
# $actionname as string scalar
# $actiontype as long scalar
# action is reassign
# do any setup for the action here
# Empty the string at the beginning of the action
$entity->SetFieldValue("action_reason", "");
}