1

I have the method below that posts a comment to a work-item in Azure DevOps.

How can i @ a user in the comment?

The Two examples below just posts a string that is @firstName lastNameand not tagging the user.

pMessage = "@User you need to take a look at this workitem"

pMessage = "@firstName lastName <mail> you need to take a look at this workitem"

public async Task PingUser(List<int> pId, string pMessage, VssConnection pConnection)
{
    WorkItemTrackingHttpClient client = pConnection.GetClient<WorkItemTrackingHttpClient>();

    foreach (var id in pId)
    {
        await client.UpdateWorkItemAsync(
            new JsonPatchDocument()
            {new JsonPatchOperation(){
                Operation = Operation.Add,
                Value = pMessage,
                Path = "/fields/System.History",
            }}, id);
    }
}
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
PEPEGA
  • 2,214
  • 20
  • 37
  • 1
    Very agree with Shayki's answer. You can also refer to this ticket: https://stackoverflow.com/questions/49103616/vsts-uploading-via-an-excel-macro-and-getting-mentions-to-work . If it is not work for you, feel free to leave comment there:-) – Mengdi Liang Oct 28 '19 at 04:44

1 Answers1

3

If you perform Get operation you can see the format you need:

var wi = workitemClient.GetWorkItemAsync("project", id).Result;

The wi.Fields["System.History"] value is:

enter image description here

So the format is:

<a href="#" data-vss-mention="version:2.0,userid"></a>

Replace the userid with the User Id, to get it you can use User Entitlements - List Rest API.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • 1
    You can also find the ID by manually mentioning a specific user in a comment and then inspecting it in the Browser – TomSelleck Nov 08 '21 at 11:39