Search code examples
c#xmltfsworkitem

How to get active directory userid from a string field of a work item


By synchronizing a project plan from a MS Project .mpp to TFS, I want to sync a field that is a string representing the name of the project manager affected to a project. As a rule, this string is taken from Active Directory's valid users group in TFS.

I am searching for a way to obtain the userid as well in order to query a SQL Server DB. Is there a was to get the userid from AD when you have the user's name? This seems to be an option, whereas not the best.

If there would be a way to capture the userid in this field as well at the same time that i sync the project manager's full name, this would be the best alternative. Any suggestions?

<FIELD name="Project Manager" refname="Custom.ProjectManager" type="String" reportable="dimension">
<HELPTEXT>The name of the project manager.</HELPTEXT>
<SUGGESTEDVALUES expanditems="true" filteritems="excludegroups">
  <LISTITEM value="[global]\Project Collection Valid Users" />
</SUGGESTEDVALUES>
</FIELD>

Solution

  • This is a workaround I tought of. The downside is that the USERID is shown whenever you see the name of the project manager.

    Work item type XML file

        <FIELD name="Project Manager" refname="Custom.ProjectManager" type="String" reportable="dimension">
        <HELPTEXT>The name of the project manager.</HELPTEXT>
        <SUGGESTEDVALUES expanditems="true" filteritems="excludegroups">
          <LISTITEM value="(ID='DOEJ24') John Doe " />
          <LISTITEM value="(ID='DOEJ23') Jane Doe " />
          <LISTITEM value="(ID='SMIJ03') John Smith " />
          <LISTITEM value="(ID='COSG01') George Constanza " />
          <LISTITEM value="(ID='BRAT99') Tom Brady " />
        </SUGGESTEDVALUES>
        </FIELD>
    

    C#

        var projectManager = WorkItemStore.GetWorkItem(Convert.ToInt32(id))["Project Manager"]);
        var pmUserId = projectManager.SubString(5, 6);
    

    This way I can easily query my database which has the project manager user id column.