2012-06-14 37 views
5

Tôi cần thay đổi trường mục công việc từ PlainText -> String. Vì tôi không thể thay đổi loại trên Mục công việc, tạo một trường mới và cập nhật giá trị của nó từ trường khác là cách tiếp cận của tôi.Giá trị TFS "Sao chép" từ một trường này sang một trường khác

Tôi đã thử "Chỉnh sửa hàng loạt các mục công việc đã chọn .." từ TFS/Web nhưng tôi không chắc liệu bạn có thể tham khảo giá trị trường khác trong mẫu đó hay không.

Làm cách nào tôi có thể đặt [Mục công việc]. [Trường mới] .Value = [Mục công việc]. [FieldOriginal] .Value ??

Điều này có thể thực hiện được nếu không phải sử dụng API TFD không?

enter image description here

Lý do tại sao tôi cần phải thay đổi kiểu lĩnh vực mục từ bản rõ để String là tôi muốn có một truy vấn với một nhà khai thác cột để kiểm tra nếu lĩnh vực này có giá trị hay không.

Đối với trường plainText, toán tử được phép duy nhất là Chứa/Không chứa. Tôi có thể ghi đè điều này để cho phép ">" không? enter image description here

Trả lời

2

Tôi có thể thực hiện qua Excel.

  1. Tạo truy vấn có cả cột trường cũ và trường mới hiển thị.
  2. Xuất truy vấn sang Excel.
  3. Sao chép và dán dữ liệu từ cột trường cũ vào trường mới.
  4. Trong Excel, từ trình đơn Nhóm nhấp vào Xuất bản để cập nhật các thay đổi trong TFS.
+1

Tôi cũng gặp vấn đề tương tự. Nhưng, tôi có thể giải quyết nó bằng giải pháp trên. Trường cũ của tôi là "Chuỗi" và loại trường là "HTML". Trường mới này trở thành chỉ đọc khi xuất sang TFS. Bất kỳ ý tưởng chỉ là hơn chào đón! –

4

Giải pháp của KMoraz không hoạt động đối với tôi, vì trường HTML trở thành chỉ đọc khi xuất sang Excel. Vì vậy, tôi đã sử dụng một kịch bản Powershell để sao chép các giá trị của một lĩnh vực thành khác (chỉ cần thay thế "$ wiFieldNewValue" biến với các lĩnh vực nguồn bạn đang sao chép)

Mã tài liệu tham khảo: Bulk update TFS work items using Powershell

Link to code

Mã nhúng:

#This script sets a specific field to a specified value for all work items in a specific project 

Function LoadTfsAssemblies() { 
Add-Type –AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
Add-Type -AssemblyName "Microsoft.TeamFoundation.WorkItemTracking.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 

} 

##### SETTINGS 
#The TFS Team Project Collection to connect to 
$tfsUri = "http://tfsserver:8080/tfs/DefaultCollection" 

#The TFS Team Project from which to select the work items 
$tfsProject = "Test Project" 

#The work item type of the work items to update 
$wiType = "Test Case" 

#The reference name of the field to update 
$wiFieldRefName = "Microsoft.VSTS.Common.Priority" 

#The value to set the field to 
$wiFieldNewValue = "1" 
##### END SETTINGS 

LoadTfsAssemblies 
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUri) 
$tfs.EnsureAuthenticated() 
if($tfs.HasAuthenticated) 
{ 
Write-Output "Successfully authenticated to TFS server [$tfsUri]" 
$workItemStore = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]) 
$query = "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.TeamProject] = '{0}' AND [System.WorkItemType] = '{1}'" -f $tfsProject, $wiType 
Write-Output("Using query [$query]") 

$workItems = $workItemStore.Query($query) 
Write-Output("Going to update [{0}] work items" -f $workItems.Count) 
$successCount = 0 
$failureCount = 0 
ForEach($wi in $workItems) { 
Write-Output("Updating work item [{0}]" -f $wi.Title) 

try { 
$wi.Open() 
$wi.Fields[$wiFieldRefName].Value = $wiFieldNewValue 
Write-Output("Set field [{0}] to [{1}]" -f $wiFieldRefName, $wiFieldNewValue) 
$validationMessages = $wi.Validate() 

if($wi.IsValid() -eq $true) 
{ 
$wi.Save() 
Write-Output("Successfully updated work item [{0}]" -f $wi.Title) 
$successCount++ 
} else { 
Write-Error("Work item is not valid!") 
ForEach($validationMessage in $validationMessages) 
{ 
Write-Error("Error: {0}" -f $validationMessage) 
} 
$failureCount++ 
} 
} catch { 
Write-Error("Couldn't set field [{0}] to [{1}] for work item [{2}]" -f $wiFieldRefName,$wiFieldNewValue,$wi.Title) 
Write-Error $_ 
$failureCount++ 
} 
} 

Write-Output("Finished!") 
Write-Output("Successfully updated: {0}" -f $successCount) 
Write-Output("Failed to update: {0}" -f $failureCount) 

} else { 
Write-Error("Couldn't authenticate to TFS server [$tfsUri]") 
} 
Các vấn đề liên quan