azure-devops

How to add person in comment section in workitem programatically in c#


I want to add email id in the comment section, like using UI we use @ symbol to add a person in the comment box.


Solution

  • Looking at some samples of this from our instance, the way this is stored within the comment text appears to be of the form:

    <a href="#" data-vss-mention="version:2.0,00000000-0000-0000-0000-000000000000">@User Name</a>

    While I haven't tried this (related to policy around our instance and writing to it) I would expect it to work if you replace the zero-GUID with the GUID of the user (corresponding to the id property of their IdentityRef), and "User Name" with the display name (displayName from their IdentityRef).

    The question currently doesn't indicate whether you're attempting to do this by directly using the REST services or through eg. the API provided by the Microsoft.TeamFoundationServer.Client nuget package; the way you will retrieve the target user's IdentityRef and save the comment is going to depend on which approach is used.