通过CQ API创建Entity,且此Entity中带有执行VALUE_CHANGED Hook的字段
采用下面这段代码希望在CQ中创建一个BaseCMActivity(添加了其他包).
需要说明的是 在UI上 选择了Project字段(该字段是个引用字段,被引用的Project为一个无状态类型)的值后, NextVersion,Owner这两个字段的ChoiceList会重新计算更新,其更新时机是在Project字段的VALUE_CHANGED Hook里面完成.
通过UI能够创建BaseCMActivity。但通过下面的代码,则提示如下错误:
E:\PerlWorkspace>cqperl createCQRecord.pl
the id is Prod00000021
6
Execution of a hook failed during the action Submit. It was the FIELD_VALUE_CHA
NGED hook of the field Project, attached to the BaseCMActivity "Prod00000021".
The reason for the failure was:
Failed condition: ent != 0
Location: ClearQuest Core:adreferencefield.cpp:75 at C:/Program Files/Rational/C
ommon/lib/perl5/site_perl/5.6.1/CQPerlExt.pm line 1515.
——————————————————————————————————————————————————————————————————————————————
use strict;
use CQPerlExt;
my $user = "admin";
my $pawd = "XXX";
my $dbName = "Prod";
my $dbSet = "SR1";
my $project = "XXX";
my $attachmentfile = "E:\PerlWorkspace\hello.pl";
#my $filename =~ s/(.*\\)(.*)/$1/;
my $headline = "发布包 filename 到 $project 项目的SIT环境";
my $description = "OK";
my $nextVersion = "XXXXXXXX";
my $entityType = "BaseCMActivity";
my $filedValue = [
["Headline",$headline],
["Project",$project],
["Owner","admin"],
["Description",$description],
["Type","Others"],
["NextVersion",$nextVersion],
];
#=========================================================================
my $currentSession = CQSession::Build();
$currentSession->UserLogon( $user, $pawd, $dbName, $dbSet );
my $currentEntity = $currentSession->BuildEntity($entityType);
my $displayname = $currentEntity->GetDisplayName();
print "the id is $displayname\n";
my $filedSize = @{$filedValue};
print $filedSize ,"\n";
for (my $x = 0; $x < $filedSize ; $x++){
$currentEntity->SetFieldValue($filedValue->[$x][0],$filedValue->[$x][1]);
}
my $attachfields = $currentEntity->GetAttachmentFields();
my $numfields = $attachfields->Count();
for (my $x = 0; $x < $numfields ; $x++)
{
my $onefield = $attachfields->Item($x);
print $onefield->GetFieldName(), "\n";
my $attachments = $onefield->GetAttachments();
if (!$attachments->AddAttachment($attachmentfile ,"attachment description"))
{
$currentSession ->OutputDebugString("Error adding attachment to record.\n");
}
}
my $status = $currentEntity->Validate();
if ($status == ""){
$status = $currentEntity->Commit();
}
else {
print "status\n";
$currentEntity->Revert();
}
CQSession::Unbuild($currentSession);