Running reports
You can use the Helix ALM SDK to run, view, and publish data-driven reports. The SDK includes the following calls for running reports:
Both calls update the CReportRunResults object, which is a list of files that report content is retrieved from. To retrieve report record list data, use the getRecordListForTable call. See Retrieving information from the Helix ALM Server for more information.
Use the getColumnsForTable call or pass one of the following column list parameters to define the report data to retrieve.
- Access
- Contains
- Name
- Owner
- Record ID
- Title
- Type
The report data is generated as a text string.
Note: Running reports may take longer than other SOAP commands. You may need to increase the amount of time your web server waits before it times out.
The following example describes how to run a report, save it to a directory, and open it in the default web browser.
1. Localize external namespaces.
using System;
using System.Collections.Generic;
using System.Text;
2. Set up the namespace, provide the login information, and define the project name.
namespace RunReport
{
class RunReport
{
static void Main (string[] args)
{
long cookie = -1;
ttsoapcgi ttsdk = null;
try
{
string username = "username";
string password = "password";
string ProjectName = "ProjectName";
3. Create an instance of the ttsoapcgi class, which is generated from the ttsoapcgi.wsdl file.
ttsdk = new ttsoapcgi();
4. Set the URL that the ttsdk object connects to if you are not using the default URL from the WSDL file.
ttsdk.Url = "http://localhost:80/scripts/ttsoapcgi.exe";
5. Select the Helix ALM project to connect to and set proj to reference it.
CProject[] projects = ttsdk.getProjectList(username, password);
CProject proj = null;
foreach (CProject p in projects)
{
if (p.database.name.Equals(projectName))
{
proj = p;
break;
}
}
6. Log in to the project.
cookie = ttsdk.ProjectLogon(proj, username, password);
7. Retrieve the list of reports available to the user.
string[] ReportColNames = ("Record ID", "Name", "Type", "Contains");
CTableColumn[] ReportCols = new CTableColumn[ReportColNames.Length];
for (int x = 0; x < ReportColNames.Length; x++)
{
ReportCols[x] = new CTableColumn();
ReportCols[x].name = ReportColNames[x];
}
CRecordListSoap ReportList = ttsdk.getRecordListForTable(cookie, "Report", "", ReportCols);
8. Print the list of reports available to the user.
Console.WriteLine("Available Reports:");
Console.WriteLine("");
9. Print the column names.
Console.WriteLine("{0} | {1} | {2} | {3}", ReportColNames[0], ReportColNames[1], ReportColNames[2], ReportColNames[3]);
Console.WriteLine("--------------------------------------------------------");
foreach (CRecordRowSoap R in ReportList.records)
{
Console.WriteLine("{0} | {1} | {2} | {3}", R.row[0].value, R.row[1].value, R.row[2].value, R.row[3].value);
}
Console.WriteLine("");
Console.Write("Please enter the record ID of the report to run: ");
bool inputSuccess = false;
long recId = 0;
while (!inputSuccess)
{
inputSuccess = true;
try
{
recId = long.Parse(Console.ReadLine());
}
catch(Exception E)
{
inputSuccess = false;
Console.WriteLine("Input Error: {0}", E.Message);
Console.Write("Please enter the record ID of the report to run: ");
}
}
Console.WriteLine("Running report: {0}", recId);
10. Run the report.
The retrieved data is stored in the CReportRunResults object and can be published or used in other ways. For example, you can publish the files to a web site or file server, or create a zip file and attach it to an auto-generated email.
CReportRunResults report = ttsdk.getReportRunResultsByRecordID(cookie, recId);
11. Create the directory using the same name as the report.
bool nameFound = false;
int y = 0;
while (y < ReportList.records.Length && !nameFound)
{
if (long.Parse(ReportList.records[y].row[0].value) == recId)
{
nameFound = true;
}
else
{
y++;
}
}
if (!nameFound)
{
throw new Exception("The specified record ID does not match any report.");
}
string DirName = "";
DirName += ReportList.records[y].row[1].value;
DirName += " ";
DirName += DateTime.Now.ToString("yyyy_MM_dd hh_mm_ss_tt");
Console.WriteLine("Creating directory: \"{0}\"", DirName);
System.IO.Directory.CreateDirectory(DirName);
string htmFileName = "";
12. Search for and save the HTML file name.
foreach (CFile f in report.mFileList)
{
if (System.Text.RegularExpressions.Regex.IsMatch(f.mstrFileName, "\\.htm"))
{
htmFileName = f.mstrFileName;
}
13. Save the data to a new file in the directory created in step 11.
System.IO.FileStream fs = System.IO.File.Create(DirName + "\\" + f.mstrFileName);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
writer.Write(f.mpFileData);
writer.Close();
fs.Close();
}
14. Verify an HTML file was located and opened.
if (htmFileName.Equals(""))
{
throw new Exception("Error: Did not find an html report file to open.");
}
15. Open the default browser.
System.Diagnostics.Process.Start(DirName + "\\" + htmFileName);
16. End the try block.
} /****************END Try block *******************/
17. Catch exceptions.
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.Message);
}
18. End the session and log out of the Helix ALM SDK.
finally
{
if (ttsdk != null && cookie != -1)
{
ttsdk.DatabaseLogoff(cookie);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}

using System;
using System.Collections.Generic;
using System.Text;
namespace RunReport
{
class RunReport
{
static void Main (string[] args)
{
long cookie = -1;
ttsoapcgi ttsdk = null;
try
{
string username = "username";
string password = "password";
string ProjectName = "ProjectName";
ttsdk = new ttsoapcgi();
ttsdk.Url = "http://localhost:80/scripts/ttsoapcgi.exe";
CProject[] projects = ttsdk.getProjectList(username, password);
CProject proj = null;
foreach (CProject p in projects)
{
if (p.database.name.Equals(projectName))
{
proj = p;
break;
}
}
cookie = ttsdk.ProjectLogon(proj, username, password);
string[] ReportColNames = ("Record ID", "Name", "Type", "Contains");
CTableColumn[] ReportCols = new CTableColumn[ReportColNames.Length];
for (int x = 0; x < ReportColNames.Length; x++)
{
ReportCols[x] = new CTableColumn();
ReportCols[x].name = ReportColNames[x];
}
CRecordListSoap ReportList = ttsdk.getRecordListForTable(cookie, "Report", "", ReportCols);
Console.WriteLine("Available Reports:");
Console.WriteLine("");
Console.WriteLine("{0} | {1} | {2} | {3}", ReportColNames[0], ReportColNames[1], ReportColNames[2], ReportColNames[3]);
Console.WriteLine("--------------------------------------------------------");
foreach (CRecordRowSoap R in ReportList.records)
{
Console.WriteLine("{0} | {1} | {2} | {3}", R.row[0].value, R.row[1].value, R.row[2].value, R.row[3].value);
}
Console.WriteLine("");
Console.Write("Please enter the Record Id of the report to run: ");
bool inputSuccess = false;
long recId = 0;
while (!inputSuccess)
{
inputSuccess = true;
try
{
recId = long.Parse(Console.ReadLine());
}
catch(Exception E)
{
inputSuccess = false;
Console.WriteLine("Input Error: {0}", E.Message);
Console.Write("Please enter the Record Id of the report to run: ");
}
}
Console.WriteLine("Running report: {0}", recId);
CReportRunResults report = ttsdk.getReportRunResultsByRecordID(cookie, recId);
bool nameFound = false;
int y = 0;
while (y < ReportList.records.Length && !nameFound)
{
if (long.Parse(ReportList.records[y].row[0].value) == recId)
{
nameFound = true;
}
else
{
y++;
}
}
if (!nameFound)
{
throw new Exception("The specified record ID does not match any report.");
}
string DirName = "";
DirName += ReportList.records[y].row[1].value;
DirName += " ";
DirName += DateTime.Now.ToString("yyyy_MM_dd hh_mm_ss_tt");
Console.WriteLine("Creating directory: \"{0}\"", DirName);
System.IO.Directory.CreateDirectory(DirName);
string htmFileName = "";
foreach (CFile f in report.mFileList)
{
if (System.Text.RegularExpressions.Regex.IsMatch(f.mstrFileName, "\\.htm"))
{
htmFileName = f.mstrFileName;
}
System.IO.FileStream fs = System.IO.File.Create(DirName + "\\" + f.mstrFileName);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
writer.Write(f.mpFileData);
writer.Close();
fs.Close();
}
if (htmFileName.Equals(""))
{
throw new Exception("Error: Did not find an html report file to open.");
}
System.Diagnostics.Process.Start(DirName + "\\" + htmFileName);
} /****************END Try block *******************/
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.Message);
}
finally
{
if (ttsdk != null && cookie != -1)
{
ttsdk.DatabaseLogoff(cookie);
}
Console.WriteLine("");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
} // End Main()
}
}
}