I want to get the display name of the assigned user on an Azure DevOps work item.
// Get client
VssConnection connection = GetVssConnection(_azureDevopsOptions);
WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
// Define fields
string startDateField = "Microsoft.VSTS.Scheduling.StartDate";
string finishDateField = "Microsoft.VSTS.Scheduling.FinishDate";
string assignedToField = "System.AssignedTo";
// Get work item
var workitemTask = await workItemTrackingHttpClient.GetWorkItemAsync(taskId);
// Get fields from work item
var startDate = workitemTask.Fields.ContainsKey(startDateField) ? workitemTask.Fields[startDateField] : 0;
var finishDate = workitemTask.Fields.ContainsKey(finishDateField) ? workitemTask.Fields[finishDateField] : 0;
var assignedTo = workitemTask.Fields.ContainsKey(assignedToField) ? workitemTask.Fields[assignedToField] : 0;
CodePudding user response:
If I remember correctly, you should parse the value of assignedToField
into a JObject
:
JObject identity = JObject.FromObject(workitemTask.Fields[assignedToField]);
Then the display name is available as identity["DisplayName"]
.