TFS 2010 Work Item is not ready to save but there are no validation items

情到浓时终转凉″ 提交于 2019-12-10 03:10:54

问题


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;
              }
            }
        }

回答1:


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.



来源:https://stackoverflow.com/questions/8358182/tfs-2010-work-item-is-not-ready-to-save-but-there-are-no-validation-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!