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

using System;
using System.Collections.Generic;
using System.Text;
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";
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);
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 which are used");
Console.WriteLine("if you press the \"Enter\" key without typing any input.");
Console.WriteLine("");
CField[] custFields = ttsdk.getCustomFieldsDefinitionList(cookie, "Defect");
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;
}
}
def.customFieldList = custFields;
ttsdk.saveDefect(cookie, def);
Console.WriteLine ("Finished editing defect");
}
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.Message);
}
finally
{
if (ttsdk != null && cookie != -1)
{
ttsdk.DatabaseLogoff(cookie);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
private static void promptForBoolean(CBooleanField bF)
{
Console.WriteLine("Checkbox field: {0}", bF.name);
bool inputGood = false;
ConsoleKeyInfo input;
char inputValue = '?';
while (!inputGood)
{
Console.Write("Set this checkbox 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 type 'y' for yes, or 'n' for no.");
}
}
if (inputValue == 'y')
{
bF.value = true;
}
else
{
bF.value = false;
}
Console.WriteLine("");
}
private static void promptForString(CStringField sF)
{
string buffer = "";
string input = "";
//determine if the field is single-line or multi-line
if (sF.isMultilineStringSpecified && sF.isMultilineString)
{
Console.WriteLine("Multi-Line String field: {0}", sF.name);
Console.WriteLine("Please type the value to save to this field.");
Console.WriteLine("Type zzzz by itself on a line to end text input.");
input = Console.ReadLine();
while (!input.Equals("zzzz"))
{
buffer = buffer + input;
input = Console.ReadLine();
}
}
else //single-line
{
Console.WriteLine("Single-line string field: {0}", sF.name);
Console.WriteLine("Please type the value to save to this field.");
buffer = Console.ReadLine();
}
sF.value = buffer;
Console.WriteLine("");
}
private static void promptForInt(CIntegerField iF)
{
Console.WriteLine("Integer Field: {0}", iF.name);
Console.WriteLine("Please type the value to save to this field: ");
bool inputGood;
int inputValue = int.MinValue;
do
{
inputGood = true;
try
{
inputValue = int.Parse(Console.ReadLine());
}
catch (Exception E)
{
Console.WriteLine(E.Message);
inputGood = false;
Console.WriteLine("Please enter an integer value: ");
}
} while (!inputGood);
iF.value = inputValue;
Console.WriteLine("");
}
private static void promptForDec(CDecimalField dF)
{
Console.WriteLine("Decimal Field: {0}", dF.name);
Console.WriteLine("Please type the value to save to this field: ");
bool inputGood;
double inputValue = double.NaN;
do
{
inputGood = true;
try
{
inputValue = double.Parse(Console.ReadLine());
}
catch (Exception E)
{
Console.WriteLine(E.Message);
inputGood = false;
Console.WriteLine("Please enter a decimal value: ");
}
} while (!inputGood);
dF.value = inputValue;
Console.WriteLine("");
}
private static void promptForDateTime(CDateTimeField tF)
{
Console.WriteLine("DateTime field: {0}", tF.name);
Console.WriteLine("Please enter the date and time to set for the field [{0}]: ", DateTime.Now.ToString());
bool inputGood;
DateTime inputValue = DateTime.Now;
do
{
inputGood = true;
IFormatProvider culture = System.Globalization.CultureInfo.CurrentCulture;
string inputBuffer;
inputBuffer = Console.ReadLine();
if (inputBuffer.Equals(""))
{
Console.WriteLine("Using current Date and Time as default.");
}
else
{
try
{
inputValue = DateTime.Parse(inputBuffer, culture);
}
catch (Exception E)
{
inputGood = false;
Console.WriteLine(E.Message);
Console.WriteLine("Please enter the date and time to set for the field [{0}]: ", DateTime.Now.ToString());
}
}
} while (!inputGood);
tF.value = inputValue;
//the valueSpecified member variable specifies whether the checkbox to enable/disable the field
//in the Helix ALM Client, is checked. Generally, if you are setting a value, you should set
//valueSpecified = true.
tF.valueSpecified = true;
Console.WriteLine("");
}
private static void promptForDate(CDateField dF)
{
Console.WriteLine("Date field: {0}", dF.name);
Console.WriteLine("Please enter the date to set for the field [{0}]: ", DateTime.Now.ToShortDateString());
bool inputGood;
DateTime inputValue = DateTime.Now;
do
{
inputGood = true;
IFormatProvider culture = System.Globalization.CultureInfo.CurrentCulture;
string inputBuffer;
inputBuffer = Console.ReadLine();
if (inputBuffer.Equals(""))
{
Console.WriteLine("Using current Date as default.");
}
else
{
try
{
inputValue = DateTime.ParseExact(inputBuffer, "d", culture);
}
catch (Exception E)
{
inputGood = false;
Console.WriteLine(E.Message);
Console.WriteLine("Please enter the date to set for the field [{0}]: ", DateTime.Now.ToShortDateString());
}
}
} while (!inputGood);
dF.value = inputValue;
//the valueSpecified member variable specifies whether the checkbox to enable/disable the field
//in the Helix ALM Client, is checked. Generally, if you are setting a value, you should set
//valueSpecified = true.
dF.valueSpecified = true;
Console.WriteLine("");
}
private static void promptForDropDown(CDropdownField dF)
{
string input = "";
bool bFound = false;
while (bFound == false)
{
Console.WriteLine("Dropdown field: {0}", dF.name);
Console.WriteLine("");
Console.WriteLine("Defined values: ");
foreach (CFieldValue val in dF.dropdownValues)
{
Console.WriteLine(" * {0}", val.value);
}
Console.WriteLine("Please enter the value for the dropdown field: ");
input = Console.ReadLine();
//check to make sure the input value matches one of the valid input values
foreach (CFieldValue val in dF.dropdownValues)
{
if (val.value.Equals(input))
{
bFound = true;
break;
}
}
}
dF.value = input;
Console.WriteLine("");
}
private static void promptForMultiDropDown(CMultiSelectDropdownField dF)
{
//To set the value for a Multi-Select DropDown Menu field, create
//an array of CFieldValue objects, and set the CMultiSelectDropdownField.values
//member variable to reference that array.
string input = "";
bool bDone = false;
bool bFound = false;
//Declare an ArrayList
System.Collections.ArrayList userValues = new System.Collections.ArrayList();
Console.WriteLine("Multi-Select Dropdown field: {0}", dF.name);
Console.WriteLine("");
Console.WriteLine("Defined values: ");
foreach (CFieldValue val in dF.dropdownValues)
{
Console.WriteLine(" * {0}", val.value);
}
Console.WriteLine("Please enter values (one per line) for the dropdown field (enter zzzz when finished):");
input = Console.ReadLine();
while (!bDone)
{
//check to make sure the input value matches one of the valid input values,
//or the special value "zzzz" to end.
if (!input.Equals("zzzz"))
{
bFound = false;
foreach (CFieldValue val in dF.dropdownValues)
{
if (val.value.Equals(input))
{
bFound = true;
//Create new CFieldValue objects to add to the ArrayList.
CFieldValue newVal = new CFieldValue();
newVal.value = input
userValues.Add(newVal);
break;
}
}
if (!bFound)
{
Console.WriteLine("Invalid value!");
}
Console.WriteLine("Please enter another value, or \"zzzz\" to finish.");
input = Console.ReadLine();
}
else
{
bDone = true;
}
} //end while(!bDone)
//Since values expects an Array, not an ArrayList, call the ToArray method,
//which allows you to create an Array from the ArrayList.
dF.values = (CFieldValue[]) userValues.ToArray(typeof(CFieldValue));
Console.WriteLine("");
}