0

To create a workitem I need to specify its fields but where exactly can I see all the possible "field paths" on my AzureDevOps site? I've edited an existing workitem and added some more fields to it but I cant seem to find the needed "field path" for my JsonPatchOperation.

Any ideas? Thanks in advance!

public static WorkItem CreateWorkItem(VssConnection connection, string title, string type, string description, string tags)
    {

        string project = "xxx";
  
        // Construct the object containing field values required for the new work item
        JsonPatchDocument patchDocument = new JsonPatchDocument();

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.Title", <-- field path
                Value = title
            }
        );

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.Description", <-- field path
                Value = description
            }
        );

 

        // Get a client        
        WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();

        // Create the new work item
        WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project, type).Result;

        Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);

        return newWorkItem;
    }
HereToLearn
  • 118
  • 7

2 Answers2

0

You can use the process template editor to see all fields in your org.

  • Install Process Editor to VS: enter image description here

  • Open Fields Browser:

enter image description here

  • Check needed fields:

enter image description here

Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
0

Another way: using the rest api.

WorkItemTrackingProcessHttpClient ProcessHttpClient = Connection.GetClient<WorkItemTrackingProcessHttpClient>();

string processName = "My New Process"; //existing process
string witName = "Task"; //existing work item type
Guid procId;
string witRefName;

GetProcAndWIT(processName, witName, out procId, out witRefName);

ShowCurrentFields(procId, witRefName);



    private static void ShowCurrentFields(Guid procId, string witRefName)
    {
        var fields = ProcessHttpClient.GetAllWorkItemTypeFieldsAsync(procId, witRefName).Result;

        Console.WriteLine("{0, -20} : {1, -40} : {2, -10} : {3, -8} : {4, -8} : {5, -8}", 
            "Name", "Reference Name", "Type", "Required", "ReadOnly", "Default");


        foreach (var field in fields)
        {
            Console.WriteLine("------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("{0, -20} : {1, -40} : {2, -10} : {3, -8} : {4, -8} : {5, -8}",
                field.Name, field.ReferenceName, field.Type, field.Required, field.ReadOnly, field.DefaultValue);
        }

        Console.WriteLine("------------------------------------------------------------------------------------------------------------\n\n\n\n");
    }

    private static void GetProcAndWIT(string processName, string witName, out Guid procId, out string witRefName)
    {
        procId = GetProcessGuid(processName);
        if (procId == null)
        {
            throw new Exception("Can not find process.");
        }

        witRefName = GetWITrefName(procId, witName);
        if (string.IsNullOrEmpty(witRefName))
        {
            throw new Exception("Can not find work item type.");
        }
    }

    private static Guid GetProcessGuid(string processName)
    {
        Guid newProcessGuid = Guid.Empty;

        var processes = ProcessHttpClient.GetListOfProcessesAsync().Result;

        return (from p in processes where p.Name == processName select p.TypeId).FirstOrDefault();
    }

    private static string GetWITrefName(Guid procGuid, string witName)
    {
        var wiTypes = ProcessHttpClient.GetProcessWorkItemTypesAsync(procGuid).Result;

        return (from p in wiTypes where p.Name == witName select p.ReferenceName).FirstOrDefault();
    }
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31