IBM Support

How to execute a specific Personal or Public query using the CleearQuest API and redirect the output to html

Technote (FAQ)


How do you execute a specific Personal or Public query in IBM Rational ClearQuest client using the ClearQuest APIs (Perl Script) and redirect the output to an html file?


This automation is required to save time and efforts to generate such a file which contains specific records.

Further, this script can be scheduled to run on a specific day/time using the Windows "Task Scheduler".


The below Perl Script uses the ClearQuest API and can be run on a Windows host.

Note: The ClearQuest Native Client must be installed on this machine.

The script runs a Public Folder query - "Public Queries/All Submitted". All Records which are in "Submitted" state will be the output of this query and the same will be printed to the html file as the final output.


All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

#!C:\Program Files\IBM\RationalSDLC\ClearQuest\CQperl.exe

# Make sure correct path of CQperl.exe has been given

use CQPerlExt; # Needed for general CQ API calls.

my @ClearQuestID = ();
my @Headline = ();
my @Project = ();
my @State = ();

# Building a ClearQuest session
my $session = CQPerlExt::CQSession_Build();

# Providing "admin" credentials to login to the schema

# Creating a workspace
my $workspace = $session->GetWorkSpace();

# You should have a query named "All Submitted" under Public Queries folder
# Display fields should be in the order - id, Headline, Project, State
# Filter of the query should be set to "where state = Submitted"
# This query must be configured correctly on a ClearQuest Client
# This script simply runs this query, gets the same results and puts into a html file
# The user logged in should have "Public Folder" privileges. A user can use "Personal" queries also

# Returns the QueryDef associated with the specified query.
my $querydef = $workspace->GetQueryDef("Public Queries/All Submitted");
# Creating the resultset and getting the total number of records in the result
my $resultset = $session->BuildResultSet($querydef);
$recordCount = $resultset->GetRecordCount();

# Iterate through the resultset to fetch information for each record
for ($i=0;$i<$recordCount;$i++) {
$status = $resultset->MoveNext();

# Column 1 is used by ClearQuest itself. Resultset starts with Column 2.
# Please check the results of your query in client
# Make sure these fields correspond to the correct column

$ClearQuestID[$i]= $resultset->GetColumnValue(2);
$Headline[$i] = $resultset->GetColumnValue(3);
$Project[$i] = $resultset->GetColumnValue(4);
$State[$i] = $resultset->GetColumnValue(5);


# Generating a html file with the result set.
my @data =();
for ($i=0;$i<$recordCount;$i++) {

push(@data, '<br /><table border=\"2\" CELLSPACING=\"10\">');
push(@data, "<tr><td><b>ClearQuest ID -</b> $ClearQuestID[$i]</b></td>\n");
push(@data, "<td><b>State -</b> $State[$i]</td></tr>\n");
push(@data, "<tr><td><b>Headline -</b> $Headline[$i]</td>\n");
push(@data, "<br /><td><b>Project -</b> $Project[$i]</td></tr>\n\n");

#html file will be created in the current directory
open (FH, '>SubmittedRecords.html');

foreach (@data){
    print FH "$_";
close FH;

# Unbuild the session

Document information

More support for: Rational ClearQuest

Software version: 7.1.2,,

Operating system(s): Windows

Reference #: 1639941

Modified date: 2013-06-24