问题
I'm getting any of multiple errors when I try to use the Client SDK to add an existing Area to an existing Team. Here's my code:
Using oTeamClient As TeamHttpClient = Utils.Connection.GetClient(Of TeamHttpClient)
Using oWorkClient As WorkHttpClient = Utils.Connection.GetClient(Of WorkHttpClient)
oValue = New TeamFieldValue With {.Value = Area.Path, .IncludeChildren = False}
oTeams = oTeamClient.GetTeamsAsync(ProjectName).Result
oTeam = oTeams.Single(Function(Team) Team.Name.StartsWith(ProjectName))
oPatch = New TeamFieldValuesPatch With {.Values = {oValue}, .DefaultValue = $"{ProjectName}\{Area.Path}"}
oContext = New TeamContext(ProjectName, oTeam.Name)
Return oWorkClient.UpdateTeamFieldValuesAsync(oPatch, oContext).Result
End Using
End Using
The problem is that I don't know what to use for TeamFieldValuesPatch.DefaultValue
.
Here's what I've tried and the corresponding error message for each attempt:
- Nothing: "DefaultValue"
- Empty String: "VssServiceException: The default team field value must be one of this team's allowed team field values."
- Project Name: "VssServiceException: The default team field value must be one of this team's allowed team field values."
- Area Path: "VssServiceException: TF400499: You have not set your team field."
- Project Name + Area Path: "VssServiceException: The default team field value must be one of this team's allowed team field values."
Unfortunately, the documentation provides no explanation of the validation rules for this property, nor any guidance on what value we should use. It seems to indicate Project Name + Area Path, but as we can see above that doesn't work.
There's this, but it conflicts with the (obscure) hint in the documentation. There's this, but I've verified that the Area exists before the update is attempted.
What value should I use for this property?
回答1:
The above error The default team field value must be one of this team's allowed team field values
means
the area path you defined in the TeamFieldValuesPatch.DefaultValue
property must be included in the TeamFieldValuesPatch.Values
property too.
If the area path defined for DefaultValue
cannot be found in the Values
. Above error will be thrown out. See below example in c#
VssConnection _connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
WorkHttpClient workClient = _connection.GetClient<WorkHttpClient>();
TeamFieldValuesPatch patch = new TeamFieldValuesPatch();
patch.DefaultValue = "Project\\DefaultAreaPath";
List<TeamFieldValue> values = new List<TeamFieldValue> {
#defaultValue must be included in the values
new TeamFieldValue { Value = "Project\\DefaultAreaPath", IncludeChildren = false },
new TeamFieldValue { Value = "Project\\OtherAreaPath", IncludeChildren = false }
};
patch.Values = values;
TeamContext team = new TeamContext("Project", "Team");
var res = workClient.UpdateTeamFieldValuesAsync(patch, team).Result;
来源:https://stackoverflow.com/questions/65486808/errors-when-attempting-to-update-team-field-values