アクション初期化フック例

初期化フックは、アクションの開始時に複雑な初期化を実行します。例えば、このフックを使用すると、フィールドをリセットしたり、アクションのタイプに応じて、フィールドに異なる値を割り当てたりできます。

以下のコードは、ユーザーが障害を別のユーザーに再割り当てしようとするときに実行されるフックです。このフックは、再割り当てアクションの開始時に、action_reason フィールドの内容をクリアします。 このフィールドの動作が、「必須」に設定されている場合、ユーザーは、障害を再割り当てする理由を入力する必要があります。

VBScript

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 

Perl

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", "");

} 
注: スキーマで、各アクションを実行する理由をユーザーが入力する必要がある場合、 各アクションの開始時に、DEFAULT_VALUE フックを使用して [action_reason] フィールドをクリアすることができます。 前の例では、フィールドのクリアは、再割り当てアクションの場合にのみ必要とされるので、アクション初期化フックを使用するほうがより適切です。

フィードバック