问题描述
我试图以编程方式保存一个TFS工作项目,但总是得到异常:
TF237124:工作项目不是准备保存
现在,我明白这是什么告诉我 - 工作项缺少必需 - 现场或相似,我的代码是通过调用该预期:
的ArrayList的ValidationResult = wi.Validate();
在保存。但是我的ArrayList包含此调用以下任何元素。
我试着使用相同的凭据登录到TFS Web界面和创建工作项的方法,工作正常
我怎样才能找到为什么我的工作项目将不能保存?这里是我的代码:
//获取到团队项目集合的引用(如通用服务帐户进行身份验证)
使用(VAR TFS =新TfsTeamProjectCollection(tfsuri,新System.Net.NetworkCredential(My_User,密码)))
{
tfs.EnsureAuthenticated();
VAR workItemStore = GetWorkItemStore(TFS);
//创建一个新的工作项目
工作项无线=新工作项目(GetWorkItemType(类型,workItemStore));
{
//值供给为KVP - 字段名称/值
的foreach(KeyValuePair<字符串,字符串> KVP中值)
{
如果(威斯康星.Fields.Contains(kvp.Key))
{
wi.Fields [kvp.Key] .value的= kvp.Value;
}
}
为ValidationResult = wi.Validate();
}
如果(ValidationResult.Count == 0)
{
wi.State = wi.GetNextState(Microsoft.VSTS.Actions.Checkin);
wi.Save();
返回wi.Id;
}
,否则
{
返回0;
}
}
}
您的验证工作项的之前您正在改变它的状态。过渡到一个新的状态可能会导致工作项行动/待处理规则。这些可以被改变的某些字段和/或添加新的规则,以这将导致先前有效数据为无效的字段的值。
从打开状态移动到闭合状态的可能的需要有人来完成评论字段(例如) - 如果它是空,不能transission。
尝试状态改变后确认,看看是否有任何故障。
I'm trying to save a TFS Work Item programmatically but always get the exception:
TF237124: Work Item is not ready to save
Now, I understand what this is telling me - that the Work Item is missing a required field or similar - and my code is anticipating this by calling:
ArrayList ValidationResult = wi.Validate();
before the save. However my ArrayList contains no elements following this call.
I've tried logging in to the TFS web interface using the same credentials and creating a Work Item that way which works fine.
How can I discover why my Work Item won't save? Here's my code:
// get a reference to the team project collection (authenticate as generic service account)
using (var tfs = new TfsTeamProjectCollection(tfsuri, new System.Net.NetworkCredential("My_User", "password")))
{
tfs.EnsureAuthenticated();
var workItemStore = GetWorkItemStore(tfs);
// create a new work item
WorkItem wi = new WorkItem(GetWorkItemType(type, workItemStore));
{
//Values are supplied as a KVP - Field Name/Value
foreach (KeyValuePair<string,string> kvp in values)
{
if (wi.Fields.Contains(kvp.Key))
{
wi.Fields[kvp.Key].Value = kvp.Value;
}
}
ValidationResult = wi.Validate();
}
if (ValidationResult.Count == 0)
{
wi.State = wi.GetNextState("Microsoft.VSTS.Actions.Checkin");
wi.Save();
return wi.Id;
}
else
{
return 0;
}
}
}
You are validating the work item before you are changing it's state. Transitioning to a new state can cause Work Item Template actions/rules to be processed. These could be changing the values of some of your fields and/or adding new rules to the fields which would cause the previously valid data to be invalid.
Moving from an Open state to a Closed state might require someone to complete a "Review" field (for example) - if it's empty it cannot transission.
Try validating after the State change and see if there are any failures.
这篇关于TFS 2010工作项目还没有准备好保存,但没有验证项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!