I already know WorkItem.Validate
method can get an ArrayList
of fields in this work item that are not valid(msdn).
But they do seem to contain only invalid fields and thus names, but not contain any error messages, i.e. why they're invalid, which is useful for situation of submitting workitem without using the built in TFS controls.
How to get error tip like "new bug 1: TF200012: field 'Title' cannot be empty."?
For better understanding, please see the picture.
I am using VS2010 SP1 Chinese language, and the error discription is translated as above.
Visual Studio is just another client that wraps TFS error messages. You can't capture the TF* errors but you can get the FieldStatus
and print you own message.
var invalidFields = workItem.Validate();
if (invalidFields.Count > 0)
{
foreach (Field field in invalidFields)
{
string errorMessage = string.Empty;
if (field.Status == FieldStatus.InvalidEmpty)
{
errorMessage = string.Format("{0} {1} {2}: TF20012: field \"{3}\" cannot be empty."
, field.WorkItem.State
, field.WorkItem.Type.Name
, field.WorkItem.TemporaryId
, field.Name);
}
//... more handling here
Console.WriteLine(errorMessage);
}
}
else // Validation passed
{
workItem.Save();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With