TFS "Copy"从一个字段到另一个字段的值

标签 tfs workitem

我需要从纯文本 -> 字符串更改工作项字段。
由于我无法更改工作项上的类型,因此我的方法是创建一个新字段并从另一个字段更新它的值。

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

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

这甚至可能无需使用 TFD API 吗?

enter image description here

我需要将 item 字段类型从 PlainText 更改为 String 的原因是我想使用列运算符进行查询以测试该字段是否具有值。

对于纯文本字段,唯一允许的运算符是包含/不包含。我可以覆盖它以允许 ">"吗?
enter image description here

最佳答案

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]")
}

关于TFS "Copy"从一个字段到另一个字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031007/

相关文章:

tfs - Team Foundation 服务器测试

TFS 2010 : Queries based on the elements of other queries?

workitem - 我可以修改 TFS 2010 中的默认 checkin 操作吗?

Azure 板 : retrieve all Work Items from a certain board of a given team

git - TFS 中是否有相当于 Cloak 的 git 版本?

tfs - 更改 Team Foundation Server 2013 的 IP 地址

visual-studio - Scrum 方法论用于什么工作区域

TFS - 在工作项之间移动任务

tfs - 如何在 checkin 期间设置 TFS 工作项目是强制性的?

tfs - 如何使用 IterationPath 作为数据源创建新字段