悲觀記錄查看連結鉤程式碼的範例

您可利用這些範例 Script 來協助啟用和管理悲觀記錄鎖定。

適用於 BASE 動作 Action_Initialization 連結鉤的鎖定記錄 Script

sub Defect_Initialization {
    my($actionname, $actiontype) = @_;
    # $actionname as string scalar
    # $actiontype as long scalar
    # action is LockRecord
    # record type name is Defect
    # Do any setup for the action here.
	$entity->LockRecord(0);
}

適用於 RECORD_SCRIPT_ALIAS 動作的鎖定記錄 Script

sub Defect_LockRecord {
    my($result);
    my($param) = @_;
    # record type name is Defect
	$entity->LockRecord(0);
    return $result;
}

適用於 RECORD_ALIAS 動作的解除鎖定記錄 Script

sub Defect_Unlock {
    my($result);
    my($param) = @_;
    # record type name is Defect

		$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
        
           $do_unlock = 1;
        }
    
        if ($do_unlock) {
           $entity->UnlockRecord();
        }

        else {
           $result = "You are not allowed to unlock this record.";
        }
   }
    return $result;
}

意見