package com.mycompany.tfsdemo;
import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.clients.workitem.CoreFieldReferenceNames;
import com.microsoft.tfs.core.clients.workitem.WorkItem;
import com.microsoft.tfs.core.clients.workitem.files.Attachment;
import com.microsoft.tfs.core.clients.workitem.files.Attachment;
import com.microsoft.tfs.core.clients.workitem.project.Project;
import com.microsoft.tfs.core.clients.workitem.wittype.WorkItemType;
public class CreateWorkItem
{
public static void main(final String[] args)
{
//Attachment att1;
//att1 = new Attachment("","");
TFSTeamProjectCollection tpc = SnippetSettings.connectToTFS();
Project project = tpc.getWorkItemClient().getProjects().get(SnippetSettings.PROJECT_NAME);
// Find the work item type matching the specified name.
WorkItemType RequirementWorkItemType = project.getWorkItemTypes().get("要求");
// Create a new work item of the specified type.
WorkItem newWorkItem = project.getWorkItemClient().newWorkItem(RequirementWorkItemType);
// Set the title on the work item.
newWorkItem.setTitle("Example Work Item");
// Add a comment as part of the change
newWorkItem.getFields().getField(CoreFieldReferenceNames.HISTORY).setValue(
"
Created automatically by a sample
");// Save the new work item to the server.
//TODO: add attachments while creating new work item
//newWorkItem.getAttachments().add(att1);
newWorkItem.save();
System.out.println("Work item " + newWorkItem.getID() + " successfully created");
}
}