Querying items

The following example describes how to use the Helix ALM SDK to query an issue, view information stored in the fields, and use the information to create custom reports, notifications, a mobile application, or an automated alert system. You can perform similar steps to query test cases, manual test runs, requirements, and requirement documents.

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 QueryDefect

{

class QueryDefect

{

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. Optionally enable plain text support for multi-line text fields.

Note:  If you do not call the plain text function, the SDK uses the 'false' as the default value, which enables plain text. Set the value to 'true' to enable HTML-formatted text

ttsdk.formattedTextSupport(cookie, false);

8. Use ttsoapcgi.getDefect() or ttsoapcgi.getDefectByRecordId to retrieve the issue object.

Change the issue number or summary to match the issue you want to retrieve. You can set the number to '0' to search by summary.

CDefect def = ttsdk.getDefect(cookie, 17, "Summary text to search for", true);

9. Query the values in the issue object.

if (def.defectnumberSpecified)

Console.WriteLine("Defect number: {0}", def.defectnumber);

Console.WriteLine("Summary: {0}", def.summary);

Console.WriteLine("Status: {0}", def.state);

Console.WriteLine("");

 

Console.WriteLine("Standard Fields:");

Console.WriteLine("Type: {0}", def.type);

Console.WriteLine("Product: {0}", def.product);

Console.WriteLine("Entered By: {0}", def.enteredby);

Console.WriteLine("Created Date: {0}", def.datetimecreatedSpecified ? def.datetimecreated.ToString() : "N/A");

Console.WriteLine("");

 

Console.WriteLine("Press any key to continue");

Console.ReadKey();

 

Console.WriteLine("");

 

Console.WriteLine("Found By Reports:");

Console.WriteLine("");

 

foreach (CReportedByRecord report in def.reportedbylist)

{

Console.WriteLine("Reported By: {0}", report.foundby);

Console.WriteLine("Report Date: {0}", report.datefoundSpecified ? report.datefound.ToString() : "N/A");

Console.WriteLine("Description:");

Console.WriteLine(report.comments);

Console.WriteLine("");

Console.WriteLine("Report Attachments:");

10. Display attachment properties.

You can also use the data to display a graphic or media content without saving it.

foreach (CFileAttachment file in report.attachmentlist)

{

Console.WriteLine("Attachment Name: {0}", file.mstrFileName);

Console.WriteLine("Attachment Size: {0}", file.mpFileData.Length);

}

 

Console.WriteLine("");

Console.WriteLine("Press any key to continue.");

Console.ReadKey();

Console.WriteLine("");

Console.WriteLine("");

11. Print the custom fields.

Console.WriteLine("Custom Fields:");

CField[] custFieldDefs = ttsdk.getCustomFieldsDefinitionList(cookie, "Defect");

 

foreach (CField f in def.customFieldLists)

{

 

switch (f.GetType().ToString())

{

case "CBooleanField":

printBoolean((CBooleanField)f);

break;

 

case "CStringField":

printString((CStringField)f);

break;

 

case "CIntegerField":

printInt((CIntegerField)f);

break;

 

case "CDecimalField":

printDec((CDecimalField)f);

break;

 

case "CDateTimeField":

printDateTime((CDateTimeField)f);

break;

 

case "CDateField":

printDate((CDateField)f);

break;

 

case "CDropdownField":

printDropDown((CDropdownField)f);

break;

 

case "CMultiSelectDropdownField":

printMultiDropDown((CMultiSelectDropdownField)f);

break;

 

Console.Write("");

 

Console.WriteLine("");

Console.WriteLine("Press any key to continue.");

Console.ReadKey();

 

Console.WriteLine("");

Console.WriteLine("Workflow events:");

 

foreach (CEvent evt in def.eventlist)

{

Console.WriteLine("Event Name: {0}", evt.name);

Console.WriteLine("Event DateTime: {0}", evt.date);

Console.WriteLine("Event By: {0}", evt.user);

Console.WriteLine("");

}

 

Console.WriteLine("Finished displaying defect data.");

} /****************END Try block *******************/

12. Catch exceptions.

catch (Exception e)

{

Console.WriteLine("An exception occurred:");

Console.WriteLine(e.Message);

}

13. 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();

 

}

 

} //END main()

/****************************************************/

 

private static CField getField(CField[] defArray, string name)

{

foreach (CField f in defArray)

{

if (name.Equals(f.name))

return f;

}

 

return null;

} //END getField()

 

private static void printBoolean(CBooleanField f)

{

Console.WriteLine("Field Type: Checkbox");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Checked: {0}", f.value);

}

 

private static void printString(CStringField f)

{

if (f.isMultilineStringSpecified && f.isMultilineString)

{

Console.WriteLine("Field Type: Multi-Line Text");

}

 

else

{

Console.WriteLine("Field Type: Text");

}

 

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field Contents:");

Console.WriteLine(f.value);

} //END printString()

 

private static void printInt(CIntegerField f)

{

Console.WriteLine("Field Type: Integer");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field Value: {0}", f.value);

} //END printInt()

 

private static void printDec(CDecimalField f)

{

Console.WriteLine("Field Type: Decimal");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field Value: {0}", f.value);

} //END printDec()

 

private static void printDateTime(CDateTimeField f)

{

Console.WriteLine("Field Type: DateTime");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field enabled: {0}", f.valueSpecified);

Console.WriteLine("Field Value: {0}", f.value);

} //END printDateTime()

 

private static void printDate(CDateField f)

{

Console.WriteLine("Field Type: Date");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field enabled: {0}", f.valueSpecified);

Console.WriteLine("Field Value: {0}", f.value);

} //END printDate()

 

private static void printDropDown(CDropdownField f)

{

Console.WriteLine("Field Type: Dropdown Menu");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field Value: {0}", f.value);

}

 

private static void printMultiDropDown(CMultiSelectDropdownField f)

{

Console.WriteLine("Field Type: Dropdown Menu");

Console.WriteLine("Field Name: {0}", f.name);

Console.WriteLine("Field Values:");

 

foreach (CFieldValue v in f.values)

{

Console.WriteLine(v.value);

}

}