【CQ需求实现】3. 对某些字段做自定义的历史操作审计
【CQ需求实现】3. 对某些字段做自定义的历史操作审计
步骤如下:
1。给记录类型添加note包,checkin后,“注释表单”即以添加到记录表单项里;
2。添加全局脚本AppendHist,脚本如下:
sub AppendHist {
# histEntryField As String
# histLogField As String
my ($histEntryField, $histLogField) = @_;
my $oldField;
my $session, $myName, $thisHist, $oldFieldValue, $newFieldValue;
my $oldHist, $newHist, $crLf, $month, $now;
# First check to see if field was empty before.
# If so, do not write a history record.
$oldField = $entity->GetFieldOriginalValue($histEntryField);
if ($oldField->GetValueStatus() eq $CQPerlExt::CQ_HAS_VALUE) {
# Compare old value and new value.
$oldFieldValue = $entity->GetFieldOriginalValue($histEntryField)->GetValue();
$newFieldValue = $entity->GetFieldValue($histEntryField)->GetValue();
if ($oldFieldValue ne $newFieldValue) {
# Get existing history so can append to it.
$oldHist = $entity->GetFieldValue($histLogField)->GetValue();
# Get current date, plus user name for entry.
$session = $entity->GetSession();
$myName = $session->GetUserLoginName();
$crLf = "\x0d\x0a";
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $time) = localtime();
$now = sprintf("%2.2d/%2.2d/%4d %2.2d:%2.2d:%2.2d", $mon + 1,$mday, $year + 1900, $hour, $min, $sec);
$thisHist = "" . $histEntryField . " 由 " . $myName ."于". $now.$crLf."由原来的:".$crLf.$oldFieldValue .$crLf. "更改为" .$crLf. $newFieldValue.$crLf ;
$newHist = $oldHist . $thisHist;
$entity->SetFieldValue($histLogField, $newHist);
}
}
}
3。选择自定义的字段,在字段的“更改的值”里加入 AppendHist($fieldname,"Notes_Log")
这样字段在更改了值后会自动添加操作审计到注释日志里;
搜索更多相关主题的帖子:
字段 定义 需求 历史