通知フックは、一連の変更がデータベースにコミットされた後、追加のアクションを起動します。例えば、1 人以上のユーザーに電子メール通知を送信したり、関連レコードを変更したりできます。(電子メール メッセージを送信する電子メール ルールを作成することもできます。「 電子メール ルールの作成」を参照してください。)
電子メール通知フックを変更した場合は、その都度、Rational® ClearQuest® メール サービスを停止して再起動する必要があります。
以下の例では、変更された障害のフィールドごとにウィンドウを開きます。また、通知フックを使用して電子メールを生成し、それを該当する配布リストに送信することもできます。
フックによって開始されたアクションは、フック スクリプトのセッション変数 CQHookExecute を値 1 に設定しない限り、通知をトリガしません。この変数は、VBScript では Long データ タイプ、Perl では long スカラです。
Sub swbug_Notification(actionname, actiontype)
' actionname As String
' actiontype As Long
' action = modify
' Note: don't use MsgBox for web-based databases
MsgBox "Modify action completed, notification hook started"
fieldnames = GetFieldNames
If IsArray(fieldnames) Then
I = LBound(fieldnames)
limit = UBound(fieldnames) + 1
' Get three kinds of values
Do While I < limit
onename = fieldnames(I)
Set oldinfo = GetFieldOriginalValue(onename)
Set newinfo = GetFieldValue(onename)
oldstat = oldinfo.GetValueStatus
If oldstat = AD_HAS_NO_VALUE Then
oldempty = True
Else
oldempty = False
oldval = oldinfo.GetValue
End If
newstat = newinfo.GetValueStatus
If newstat = AD_HAS_NO_VALUE Then
newempty = True
Else
newempty = False
newval = newinfo.GetValue
End If
' Compare the values
If oldstat = AD_VALUE_UNAVAILABLE Then
MsgBox "Field " & onename & ": original value unknown"
Else
If newempty And Not oldempty Then
MsgBox "Field " & onename & " had its value deleted"
ElseIf oldempty And Not newempty Then
MsgBox "Field " & onename & " now= " & newval
ElseIf oldval <> newval Then
MsgBox "Field " & onename & " was= " & oldval
MsgBox "Field " & onename & " now= " & newval
Else
MsgBox "Field " & onename & " is unchanged"
End If
End If
I = I + 1
Loop
End If
MsgBox "Modify action and notification hook completed"
End Sub
sub swsub_Notification {
my($actionname, $actiontype) = @_;
# $actionname as string scalar
# $actiontype as long scalar
# action is Submit
# Post-commit notifications about actions may be handled here
my ($fieldnames,
$session,
$fieldname,
$oldinfo,
$newinfo,
$newstat,
$oldstat,
$oldval,
$oldempty,
);
$session = $entity->GetSession();
$fieldnames = $entity->GetFieldNames();
# Get three kinds of values
foreach $fieldname (@$fieldnames) {
$oldinfo = $entity->GetFieldOriginalValue($fieldname);
$newinfo = $entity->GetFieldValue($fieldname);
$oldstat = $oldinfo->GetValueStatus();
if ($oldstat == $CQPerlExt::CQ_HAS_NO_VALUE) {
$oldempty = 1;
} else {
$oldempty = 0;
$oldval = $oldinfo->GetValue();
}
$newstat = $newinfo->GetValueStatus();
if ($newstat == $CQPerlExt::CQ_HAS_NO_VALUE) {
$newempty = 1;
} else {
$newempty = 0;
$newval = $oldinfo->GetValue();
}
# Compare the values
if ($oldstat == $CQPerlExt::CQ_VALUE_UNAVAILABLE) {
$session->OutputDebugString("Field " . $fieldname . ":
original value unknown¥n");
} else {
if ($newempty && !$oldempty) {
$session->OutputDebugString ("Field " & $fieldname .
" had its value deleted¥n");
} elsif ($oldempty && !$newempty) {
$session->OutputDebugString ("Field " . $fieldname . " now = " .
$newval. "¥n");
} elsif ($oldval != $newval) {
$session->OutputDebugString ("Field " . $fieldname . " was = " .
$oldval. "¥n");
$session->OutputDebugString ("Field " . $fieldname . " now = " .
$newval. "¥n");
} else {
$session->OutputDebugString ("Field " . $fieldname . " is
unchanged¥n");
}
}
}
$session->OutputDebugString ("Modify action & notification hook completed¥n");
}