IBM Support

How do you find out number of records submitted from the start date of the current month till today's date using Rational ClearQuest APIs

Question & Answer


Question

How to find out number of records submitted from the start date of the the current month till today's date using IBM Rational ClearQuest APIs?

Cause

This is required to get an instant information on the number of records submitted from the start date of the current month till today's date without logging into Rational ClearQuest Client.

Answer

The Perl Script below uses the ClearQuest API and can be run on Windows.
Note: The ClearQuest Native Client must be installed on this machine.

This script iterates through all the ClearQuest Records to find all the Records which are submitted in the current month, from the start date of the current month till today's date.
This script will print total number of such records to the command prompt.

Steps to run this script:
  1. Navigate to the location where CQperl.exe is installed.
    By default: C:\Program Files\IBM\RationalSDLC\ClearQuest\CQperl.exe

     
  2. Save the following Perl script text to notepad and save with a .pl extension.
    *******************************
    #!C:\Program Files\IBM\RationalSDLC\ClearQuest\CQperl.exe
    # Make sure you have correct path for CQperl.exe

    use CQPerlExt;

    # Create a Rational ClearQuest admin session
    my $CQSession = CQPerlExt::CQSession_Build();

    # Logon as admin
    # Provide correct values for admin password, User Database, and Schema Repository na
    $CQSession->UserLogon("admin","<adminPassword>","<userDatabase>","<SchemaRepositoryName>");

    use POSIX qw(strftime);
    my $now = time();

    # Getting the values for Today's date and the Start date of the month
    # This script reads the current date from the machine it is being run and
    #accordingly it calculates the start date of the month
    my $timezone = strftime("%z", localtime($now));
    $timezone =~ s/(\d{2})(\d{2})/$1:$2/;
    my $EndDate = strftime("%Y-%m-%d", localtime($now)) . $tz . "\n";
    my @arrayenddate = $EndDate;
    my $StartDate = substr($EndDate, 0, 7);
    $StartDate = $StartDate . "-01";
    my @dateRange = ("$StartDate", "$EndDate");
    $querydef = $CQSession->BuildQuery("defect");
    $querydef->BuildField("id");

    $operator = $querydef->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_AND);
    $operator->BuildFilter("Submit_Date", $CQPerlExt::CQ_COMP_OP_BETWEEN, \@dateRange);
    $resultset = $CQSession->BuildResultSet($querydef);

    $resultset->EnableRecordCount();
    $resultset->Execute();
    $recordCount = $resultset->GetRecordCount();
    print "Total number of records submitted from the Start Date of current month till today's date are - $recordCount\n";

    #Unbuild the Admin session
    CQPerlExt::CQSession_Unbuild($CQSession);
    *******************************

     
  3. Run the script using the following command:
    cqperl <filename.pl>

[{"Product":{"code":"SSSH5A","label":"Rational ClearQuest"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"API","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.1.2.3;7.1.2.7;7.1.2.9","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
21 March 2021

UID

swg21649015