UnlockRecord

説明

レコードのロックを解除します。ロックを削除できるのは、ロックを所有するユーザー、スーパー ユーザー権限を持つユーザー、またはスキーマ デザイナが許可するユーザーのみです。レコードが別のユーザーや別のセッションによってロックされているか、またはレコードが更新されたことを示す例外がスローされます。

アクセスがコミットされるか元に戻されると、レコードのロックが自動的に解除されます。RECORD_SCRIPT_ALIAS フックを使用して、中止されたロックを手動で削除することができます。

レコードを手動でアンロックできるようにするには、レコード タイプごとに次のようにします。
  • Unlock という名前の新規レコード スクリプトを作成します。
  • タイプが RECORD_SCRIPT_ALIAS の Unlock という名前の新規アクションを追加します。
  • Unlock スクリプトにアクション Record Script を設定します。
注: このメソッドは、バージョン 7.1 で使用可能になります。

構文

VBScript

entity.UnlockRecord  

Perl

$entity->UnlockRecord(); 
識別子
説明
entity
Entity オブジェクトは、ユーザー データ レコードを表します。構文のこの部分を省略すると、フック内では、現在のデータ レコードに対応する Entity オブジェクトが想定されます (VBScript のみ)。
戻り値
なし。

VBScript

Function Defect_Unlock(param)
  ' param As Variant
  ' record type name is Defect
    REM add your hook code here
    Dim result
    Dim session
    Dim locked_by
    ' Get the session
    set session = GetSession
    locked_by = GetLockOwner
    if (locked_by <> "") then
        Dim do_unlock
        do_unlock = session.IsUserSuperUser
        if (NOT do_unlock) then
            ' If the current user holds the lock, let them unlock it.
            Dim username
            username = session.GetUserLoginName
            if (username = locked_by) then
                do_unlock = true
            end if
        end if
        if (NOT do_unlock) then
            ' Additional options to "authorize" unlocking:
            '
            ' 1) allow if user is a member of an "unlock" group
            '    get user's groups, check if member
            '
            ' 2) allow for some privileged users, e.g. Security Administrator
            '    check session for the chosen privilege
            '
            ' 3) many other possibilities
        end if
        if (do_unlock) then
            UnlockRecord
        else
            result = "You are not allowed to unlock this record."
        end if
    end if
End Function

Perl

sub Defect_Unlock {
    my($result);
    my($param) = @_;
    # record type name is Defect
    if (ref ($param) eq "CQEventObject") {
        # add your CQEventObject parameter handling code here
    } elsif (ref (¥$param) eq "SCALAR") {
        # add your scalar parameter handling code here
        # The Web clients support scalar parameter type only,
        # so the hook code added in the above section, needs to be duplicated here
    } else {
        # add your handling code for other type parameters here, for example:
        # die("Unknown parameter type");
    }
    $result = "";
    my $locked_by = $entity->GetLockOwner();
    if ($locked_by ne "") {
        my $do_unlock = $session->IsUserSuperUser();
        if (! $do_unlock) {
            # If the current user holds the lock, let them unlock it.
            my $username = $session->GetUserLoginName();
            if ($username =~ /^$locked_by$/i) {
                $do_unlock = 1;
            }
        }
        if (! $do_unlock) {
            # Additional options to "authorize" unlocking:
            #
            # 1) allow if user is a member of an "unlock" group
            #    get user's groups, check if member
            #
            # 2) allow for some privileged users, e.g. Security Administrator
            #    check session for the chosen privilege
            #
            # 3) many other possibilities
        }
        if ($do_unlock) {
            $entity->UnlockRecord();
        }
        else {
            $result = "You are not allowed to unlock this record.";
        }
    }
    return $result;
}

フィードバック