Populating custom fields

The following example describes how to populate issue custom fields. You can perform similar steps to populate the custom fields for test cases, manual test runs, requirements, and requirement documents.

Custom fields must exist in the item you are editing. If no custom fields exist, you need to create them in the Helix ALM Client first.

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 CustomFields

{

class CustomFields

{

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. Use ttsoapcgi.editDefect() or ttsoapcgi.editDefectByRecordId() to retrieve and lock the record.

This prevents other clients or SOAP applications from editing the record. To search for an issue by summary, set the issue number to 0 and the summary to a non-empty string.

CDefect def = ttsdk.editDefect(cookie, 0, "Example Defect 1, With Formatted Text.", false);

Console.WriteLine("Editing defect number {0}, \"{1}\"", def.defectnumber, def.summary);

Console.WriteLine("Please enter values for the following custom fields.");

Console.WriteLine("At prompts, values in parentheses, e.g. \"(y/n)\" indicate valid input values,");

Console.WriteLine("values in square brackets, e.g. [1/1/2011] indicate default values that are used");

Console.WriteLine("if you press the \"Enter\" key without typing any input.");

Console.WriteLine("");

8. Retrieve the list of custom fields for the issue.

The getCustomFieldsDefinitionList displays all available values for each drop-down field.

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

9. Set the field types for the prompts used to populate the custom fields.

foreach (CField f in custFields)

{

switch (f.GetType().Name)

{

case "CBooleanField":

promptForBoolean((CBooleanField)f);

break;

 

case "CStringField":

promptForString((CStringField)f);

break;

 

case "CIntegerField":

promptForInt((CIntegerField)f);

break;

 

case "CDecimalField":

promptForDec((CDecimalField)f);

break;

 

case "CDateTimeField":

promptForDateTime((CDateTimeField)f);

break;

 

case "CDateField":

promptForDate((CDateField)f);

break;

 

case "CDropdownField":

promptForDropDown((CDropdownField)f);

break;

 

case "CMultiSelectDropdownField

promptForMultiDropDown((CMultiSelectDropdownField)f);

break;

}

}

10. Set the custom field list to the list populated in step 9.

def.customFieldList = custFields;

11. Save the changes.

ttsdk.saveDefect(cookie, def);

12. Finish editing the issue and catch exceptions.

Console.WriteLine ("Finished editing defect");

}

 

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

}

14. Create the prompts for custom field data.

Note:  The following example is for a Boolean field. See the complete example for other field types.

private static void promptForBoolean(CBooleanField bF)

{

Console.WriteLine("Check box field: {0}", bF.name);

 

bool inputGood = false;

ConsoleKeyInfo input;

char inputValue = '?';

 

while (!inputGood)

{

Console.Write("Set this check box to checked (y/n)? ");

input = Console.ReadKey();

 

if (input.KeyChar == 'y' || input.KeyChar == 'n')

{

inputGood = true;

inputValue = input.KeyChar;

}

else

{

Console.WriteLine("");

Console.WriteLine("Invalid input. Please enter 'y' for yes, or 'n' for no.");

}

}

 

if (inputValue == 'y')

{

bF.value = true;

}

 

else

{

bF.value = false;

}

 

Console.WriteLine("");

}