2010-09-29 8 views
9

Utilizando la API TFS, puedo crear un elemento TFS, no hay problema.¿Devuelve el ID de artículo de trabajo TFS recién creado utilizando la API TFS?

¿Cuál sería la mejor manera para que yo sepa cuál es la identificación del artículo para el artículo recién creado?

Gracias,

George

 try 
     { 
      // Authenticate User Account 
      NetworkCredential account = new NetworkCredential(USERNAME, PASSWORD, DOMAIN); 
      // for user stories from the team project where the user story will be created. 
      Uri collectionUri = new Uri(tfsURI); 
      //TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri); 
      TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri, account); 
      WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); 
      Project teamProject = workItemStore.Projects[info.TFSProjectName]; 
      WorkItemType workItemType = teamProject.WorkItemTypes[info.ItemType]; 
      // Create the work item. 
      WorkItem userStory = new WorkItem(workItemType); 
      userStory.Title = info.Title; 
      userStory.Description = info.Description; 
      userStory.AreaPath = info.AreaPath; 
      userStory.IterationPath = info.IterationPath; 
      userStory.Fields["Assigned To"].Value = info.AssignedTo; 
      if (info.ItemType == "Task") 
      { 
       userStory.Fields["Discipline"].Value = info.Discipline; 
      } 
      else if (info.ItemType == "Bug") 
      { 
       userStory.Fields["Symptom"].Value = info.Symptom; 
       userStory.Fields["Steps To Reproduce"].Value = info.StepsToReproduce; 
      } 
      else if (info.ItemType == "Change Request") 
      { 
       userStory.Fields["Justification"].Value = info.Justification; 
      } 
      // Save the new user story. 
      userStory.Save(); 
      return true; 
     } 
     catch (Exception ex) 
     { 
      log.Error("Error Creating TFS Task.", ex); 
      return false; 
     } 
     finally 
     { 
     } 
    } 

Respuesta

15

Tan pronto como guarde historias de usuario, el campo ID se rellenará. Debería poder devolver userStory.Id.

+1

Robaticus, gracias por su respuesta. Funcionó perfectamente. :) – ElMatador

Cuestiones relacionadas