Getting a list of defects and modifying a record
The following Perl example is an external program that lists all the defect records in a HCL Compass user database, and modifies one of the records. The program:
- Lists all the defect records in the SAMPL database, and selects "id," "Headline," and "State" as display fields.
- Modifies the "Description" field of the defect record SAMPL00000012 to be "This defect has been modified."
Perl
use CQPerlExt;
#Getting the session
my $session = CQSession::Build();
CQSession::UserLogon ($session, "admin", "", "SAMPL", "Lab3");
my $querydef = $session->BuildQuery ("defect");
$querydef->BuildField ("id");
$querydef->BuildField ("headline");
my $resultset = $session->BuildResultSet ($querydef);
$resultset->Execute();
while (($resultset->MoveNext()) == 1)
{
$id = $resultset->GetColumnValue(1);
$rec = $session->GetEntity("Defect", $id);
$head = $rec->GetFieldValue("Headline")->GetValue();
$state= $rec->GetFieldValue("State")->GetValue();
print "$id, $head, $state. \n";
if ($id eq "SAMPL00000012") {
$session->EditEntity($rec, "Modify");
$rec->SetFieldValue("description", "This defect has been modified.");
$rec->Validate();
$rec->Commit();
}
}
CQSession::Unbuild($session);