2012-06-14 207 views
5

我需要从PlainText - > String中更改工作项字段。 由于我无法更改工作项目上的类型,所以创建新字段并从其他字段更新它的值是我的方法。TFS从一个字段到另一个字段的“复制”值

我已经尝试过从TFS/Web“批量编辑所选择的工作项目..”,但我不确定是否可以在该模板中引用另一个字段值。

我该如何设置[Work Item]。[FieldNew] .Value = [Work Item]。[FieldOriginal] .Value ??

这甚至可能不需要使用TFD API?

enter image description here

我之所以需要改变从明文字符串项字段类型是,我想有一个列运算符的查询以测试是否字段值与否。

对于plainText字段,唯一允许的运算符是包含/不包含。我可以重写这个以允许“>”吗? enter image description here

回答

2

我无法通过Excel。

  1. 创建一个新旧字段列可见的查询。
  2. 将查询导出到Excel。
  3. 将旧字段列中的数据复制并粘贴到新字段。
  4. 在Excel中,从团队菜单中单击发布以更新TFS中的更改。
+1

我有同样的问题。但是,我可以用上面的解决方案解决它。我的旧字段是“字符串”,字段类型是“HTML”。这个新字段在导出到TFS时变为只读。任何想法都非常值得欢迎! –

4

KMoraz的解决方案也不适用于我,因为HTML字段在导出到Excel时变为只读。因此,我用PowerShell脚本一个字段的值复制到另一个(只需更换与源领域要复制的“$ wiFieldNewValue”变量)

码参考:Bulk update TFS work items using Powershell

Link to code

嵌入代码:

#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]") 
} 
相关问题