Today my dear friend Matteo asked me some help with a snippet of code to insert a WIT into a TFS. The snippet was the following one.
He is having problem because the Save throws exception.
TF237124: Work Item is not ready to save
And he was wondering what the cause is. Whenever you want to save a Work Item you need to know that there are a lot of rules that can be violated, as an example the team project I’m trying to save the WIT into, has a customized workflow for the item *Task.*The right path to do is to validate the WorkItem prior to save , and looking at errors you can simply understand what prevents the WIT from saving, the code is really simple.
Just call Validate() method of the WIT and verify each errors returned in an ArrayList object. Let’s look at what is returned in my situation inside the Arraylist returned by validate.
As you can see there is an error in the field System.State (look at the property ReferenceName), and the error can be found in the field Status that list InvalidListValue. The good stuff is that a list of Allowed Values can be found in this item, thus permitting you to look at the possible values. In my situation the only valid initial state is Proposed, so I need to add this line to the preceding snippet.
And the insert work good. So if you ever encounter a TF237124 and whenever you need to save a Work Item do not forget to check errors returned by the Validate() method.