Reputation: 6762
I am trying to create a tfs task using c# code. I am able to add task with the below code. But I am unable to add assignedto, keywords, priority etc through this. I did not find related properties in workItemType object.
I tried Fields["Keywords"] etc but it did not work for me. Any pointers please
private static readonly Uri TfsServer = new Uri("my tfs url");
static readonly TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(TfsServer);
static readonly WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
static readonly Project teamProject = workItemStore.Projects["my project name"];
static readonly WorkItemType workItemType = teamProject.WorkItemTypes["Task"];
WorkItem tfsTask = new WorkItem(workItemType)
{
Title = "Test Title",
//assignedto,
State = "Proposed",
//substatus ="Not Started",
AreaPath = @"my path",
IterationPath = @"my iteration path",
//Keywords ="my keyword",
//prioity=3
Description = "newVcDescription"
};
tfsTask.Save();
Upvotes: 2
Views: 828
Reputation: 29968
When you set the value for work item field from new WorkItem(workitemType){}
, you can only set the value for these fields provided by intellisense:
For other fields, you can set the value like this:
tfsTask.Fields["Priority"].Value = "4";
tfsTask.Fields["Assigned To"].Value = "XXX";
tfsTask.Tags = "tag1;tag2";
tfsTask.Save();
Upvotes: 2
Reputation: 316
So not all standard attributes of tfs can be called like that. Not 100% sure in C# but in powershell i would have to do something like this.
$proj = $ws.Projects["Scrum Test"]
$ProductBacklogWorkItem=$proj.WorkItemTypes["Product Backlog Item"]
$pbi=$ProductBacklogWorkItem.NewWorkItem()
// stadard attribute
$pbi.Description = $SRLongDescription
// nonstandard
$pbi["Assigned to"] = $SROwner
// custom elements
$pbi["Custom.CD.ExternalReferenceID"] = $SRTicketId
I know its a different way of calling but thought it might be helpful to understand how TFS looks at the work item attributes.
Upvotes: 2