Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

How to create a work item with multi-line description with code? #307

Description

@liangming2003

Below is code for creating a work item.

The "\r\n" in the string description is not recognized, so the description text of newly created item is on one line.

How to create a work item with multi-line description with code, thanks.

 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",
                    Value = title
                }
            );

            patchDocument.Add(
                new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path = "/fields/System.Description",
                    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;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions