조치 알림 후크 예제

알림 후크는 변경 세트가 데이터베이스에 확약되면 추가 조치를 트리거합니다. 예를 들면, 한 명 이상의 사용자에게 이메일 알림을 보내거나 관련 레코드를 수정할 수 있습니다. (이메일 메시지를 보내기 위한 이메일 규칙을 작성할 수도 있습니다. 이메일 규칙 작성을 참조하십시오.)

이메일 알림 후크를 변경할 때마다 Rational ClearQuest Mail Service를 중지한 다음 다시 시작해야 합니다.

다음 예제는 수정된 결함의 각 필드 창을 엽니다. 또한 알림 후크를 사용하여 이메일 메시지를 생성하여 적절한 분배 목록으로 보낼 수도 있습니다.

후크에서 시작된 조치는 후크 스크립트의 CQHookExecute 세션 변수를 1 값으로 설정한 경우 알림을 트리거합니다. 이 변수의 데이터 유형은 VBScript의 경우 Long이고 Perl의 경우 long scalar입니다.

VBScript

 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 
 

Perl

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

피드백