Get Workflow using code


How can I get the workflow for a Workitem.

I tried this

Get the WorkItemType, then get the FieldDefinition for "State" and the allowed values for this field definition.But I just get "Active" and "Closed".

I
′d like to get the whole Wokflow , get the transitions for a workitem and the initial state.

Can anyone help me ?

Thanks


jalekz




Today, 12:21 AM UTC
Valery Tolkov
Posts 14
AnswerRe: Workitem workflow
Was this post helpful ?


You can export workitem type using API or witexplort command line tool. It will XML document, which contains entire type definition with fields and workflow.

You can export workitem type using API or witexplort command line tool. It will XML document, which contains entire type definition with fields and workflow.

The command witexport works very well...

but, i need to get the workflow using code.

I′ve been using "Microsoft.TeamFoundation" dlls ...
but Ip havent find the way to do this..

Thanks

[5440 byte] By [jalekz] at [2007-12-20]
# 1

Hi jalekz,

1. You can download "Process templates" which your team project use. (Team ->Team Foundation Server Settings -> Process Template Manager)

2. Open the work item xml file which you want to get workflow using code. For example task.xml which under the folder (....\[your prcess templates name]\WorkItem Tracking\TypeDefinitions).

3. Edit this xml file, the code in <WORKFLOW></WORKFLOW> is you want.

4. You can define your own workflow in this section.

Thanks,

Ed

EdwardZhou-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Work Item Tracking...
# 2
OK..

But this is my scenario..

I have an application, I want to save Workitems to TFS from this application...
So I want to show user, the posible values of each Field..

Every field may has a list of allowed values. But in the case of State and Reason, the list of allowed values is dynamic, because the possible states and reasons deppends on previous state.

An i want to validate this... for example.
I have a new workitem. I render its fields in the screen, for the "state" and "reason" fields I add two combobox , as the workitem is new. the combo box state must have just the "Active" option and the combobox reason must have the "New" option..

When i press the buttons Save, this workitem is saved in TFS, and now the allowed values for state and reason must change. anh the options in both combobox also must change.

Thats the reason for I want to know the workflow for a WorkItemType.

I′ve tried using code like this. But I havent find an option to know the Workflow.

Project project = TFSServices.GetProject(89);
WorkItemType wit = project.WorkItemTypes["Requirement"];

FieldDefinition fstate = wit.FieldDefinitions["State"];
FieldDefinition freason = wit.FieldDefinitions["Reason"];

WorkItem w = wit.NewWorkItem();
w.Title = "Title from Test Application";
w.Save();

Thanks...

jalekz at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Work Item Tracking...
# 3

Oh, i see. As i know the workflow only allows people defined in workitem's template.

May be you can define this in the <WORKFLOW></WORKFLOW> in your work item template.

For example:

--

<WORKFLOW>
<STATES>
<STATE value="Active">
<FIELDS>
<FIELD refname="Microsoft.VSTS.Common.ResolvedReason">
<EMPTY />

</FIELD>
</FIELDS>
</STATE>
</STATES>
<TRANSITIONS>
<TRANSITION from="" to="Active">
<REASONS>
<DEFAULTREASON value="New" />
<REASON value="Build Failure" />
</REASONS>
</TRANSITION>
</TRANSITIONS>
</WORKFLOW>

--

This section means the field "REASONS" isn't contains any values (<EMPTY/>) when you new a work item, after you save this work item and then the value of "STATE" will be changed from " " to "Active", and then the field "REASONS" will be changed to contains the values you defined in <FIELDS></FIELDS> section.

EdwardZhou-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Work Item Tracking...

Visual Studio Team System

Site Classified