Editing workflow events

The following example describes how to edit an Assign workflow event for an issue. To edit an event, edit the record, locate the event you want to edit in the issue event list, and then edit the event. You can use similar steps to edit events for 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 EditWorkflowEvent

{

class EditWorkflowEvent

{

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. List the issues available to the logged in user and set up a CTableColumn array that passes to getRecordListForTable().

Note:  The CRecordListSoap object contains an array of records and each object in the array represents one issue. Each record contains an array of field values corresponding to the requested columns.

string[] columnNames = { "Number", "Status", "Summary" };

CTableColumn[] columns = new CTableColumn[columnNames.Length];

 

for (int x = 0; x < columns.Length; x++ )

{

columns[x] = new CTableColumn();

columns[x].name = columnNames[x];

}

CRecordListSoap DefectRecords = ttsdk.getRecordListForTable(cookie, "Defect", "", columns);

 

Console.WriteLine("");

Console.WriteLine("Available defects:");

Console.WriteLine("");

Console.WriteLine("\r\n\r\n# | Status | Summary");

Console.WriteLine("--------------------------------------");

8. Select the issue number you want to edit.

foreach (CRecordRowSoap defectRecord in DefectRecords.records)

{

Console.WriteLine("\r\n{0} | {1} | {2}", defectRecord.row[0].value,

defectRecord.row[1].value, defectRecord.row[2].value);

}

 

Console.WriteLine("");

Console.WriteLine("Please enter the number of the defect you want to edit: ");

 

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

 

CDefect def = ttsdk.editDefect(cookie, inputValue, "", false);

9. View existing events.

if (def.eventlist == null || def.eventlist.Length < 1)

{

throw new Exception("The selected defect has no workflow events.");

}

Console.WriteLine("\r\nWorkflow Events:");

Console.WriteLine("");

Console.WriteLine(" # | Event Name | Date and Time | User");

Console.WriteLine("----------------------------------------");

 

for (int x = 0; x < def.eventlist.Length; x++)

{

Console.WriteLine("{0} | {1} | {2} | {3} ", x, def.eventlist[x].name,

def.eventlist[x].date, def.eventlist[x].user);

 

}

10. Use getEventDefinitionList to check if the event is an assignment event.

CEventDefinition[] eventDefs = ttsdk.getEventDefinitionList(cookie, "Defect");

//input handling loop

do

{

inputGood = true;

 

Console.WriteLine("");

Console.WriteLine("This demonstration program is limited to only editing Assign events.");

Console.WriteLine("Please enter the number of the Assign event to edit: ");

 

try

{

inputValue = int.Parse(Console.ReadLine());

}

 

catch (Exception E)

{

Console.WriteLine(E.Message);

inputGood = false;

Console.WriteLine("Please enter an integer value: ");

}

if (inputValue < 0 || inputValue >= def.eventlist.Length)

{

Console.WriteLine("Error: The number entered was not a valid event number.");

inputGood = false;

}

 

else if (!isEventAssign(findEvtDef(eventDefs, def.eventlist[inputValue].name)))

{

Console.WriteLine("Error: The selected event is not an Assign event.");

inputGood = false;

}

 

} while (!inputGood);

 

CEvent evt = def.eventlist[inputValue];

 

Console.WriteLine("Event's current assignment list:");

Console.WriteLine("{0}", renderStringArray(evt.assigntolist));

 

Console.WriteLine("\r\n------------------------\r\n");

 

Console.WriteLine("Available Users:");

 

string[] userColumnNames = { "Name" };

CTableColumn[] userColumns = new CTableColumn[userColumnNames.Length];

11. Set up a CTableColumn array that passes the list of users to getRecordListForTable().

for (int x = 0; x < userColumns.Length; x++ )

{

userColumns[x] = new CTableColumn();

userColumns[x].name = userColumnNames[x];

}

 

CRecordListSoap userRecords = ttsdk.getRecordListForTable(cookie, "User", "", userColumns);

 

for (int x = 0; x < userRecords.records.Length; x++)

{

Console.WriteLine(" {0} | {1}", x, userRecords.records[x].row[0].value);

}

12. Create an ArrayList object to retrieve and validate user input.

System.Collections.ArrayList userArrayList = new System.Collections.ArrayList();

bool bFinished = false;

 

Console.WriteLine("Please enter the number of the user to add to the assignment list (-1 to quit):");

 

while (!bFinished)

{

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: ");

}

 

if (inputValue < -1 || inputValue >= userRecords.records.Length)

{

Console.WriteLine("Error: The number entered was not a valid user number.");

inputGood = false;

}

 

else if (inputValue != -1)

{

userArrayList.Add(userRecords.records[inputValue].row[0].value);

inputGood = false;

}

 

} while (!inputGood);

 

if (inputValue == -1)

{

if (userArrayList.Count < 1)

{

Console.WriteLine("Error: You must add at least one user to the event assignment list.");

}

else

{

bFinished = true;

}

}

} // END while (!bFinished)

13. Create an array of strings from the userArrayList and save it to the event object.

evt.assigntolist = (string[]) userArrayList.ToArray(typeof(string));

14. Save the changes.

ttsdk.saveDefect(cookie, def);

15. Finish editing the issue and catch exceptions.

Console.WriteLine ("Finished editing defect");

}

 

catch (Exception e)

{

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

Console.WriteLine(e.Message);

}

16. Update the Assign event, 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();

}

}

 

private static string renderStringArray(string[] ar)

{

string buffer = "";

 

for (int x = 0; x < ar.Length; x++)

{

buffer = buffer + ar[x];

 

if (x < (ar.Length - 1))

{

buffer = buffer + "\r\n";

}

}

 

return buffer;

}

 

private static CEventDefinition findEvtDef(CEventDefinition[] ar, string name)

//locate the Event Definition for an event by name.

 

foreach (CEventDefinition evt in ar)

{

if (evt.name.Equals(name))

return evt;

}

 

return null;

}

 

private static bool isEventAssign(CEventDefinition evt)

{

//determine if an Event Definition is an Assignment event.

 

if (evt.newAssignmentSpecified == true && evt.newAssignment == true)

return true;

else

return false;

}