简体   繁体   English

如何在C#中使用TFS rest API在现有用户故事下创建子任务?

[英]How to create child tasks under existing user story using TFS rest API in C#?

I know there is a provision for creating user story and a child task in batch call by using TFS rest API as mentioned in https://www.visualstudio.com/en-us/docs/integrate/api/wit/samples . 我知道有一条规定,可以使用https://www.visualstudio.com/zh-cn/docs/integrate/api/wit/samples中提到的TFS rest API通过批处理调用创建用户故事和子任务。

But my requirement is I already have existing user story and I want to create child tasks under existing user story in c#. 但是我的要求是我已经有现有的用户故事,并且我想在c#中的现有用户故事下创建子任务。

Does anybody is having an idea how to do this? 有人在想如何做到这一点吗?

Refer to this sample code: 请参考以下示例代码:

var url= new Uri("https://XXX.visualstudio.com");
                VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[personal access token]"));
var connection = new VssConnection(url, c);
            var workitemClient = connection.GetClient<WorkItemTrackingHttpClient>();
            string projectName = "scrum2015";
            int parentWITId = 771;
            var patchDocument = new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchDocument();
            patchDocument.Add(new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation() {
                Operation=Operation.Add,
                Path= "/fields/System.Title",
                Value="childWIT"
            });
            patchDocument.Add(new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/relations/-",
                Value = new
                {
                    rel = "System.LinkTypes.Hierarchy-Reverse",
                    url = connection.Uri.AbsoluteUri+ projectName+ "/_apis/wit/workItems/"+parentWITId,
                    attributes = new
                    {
                        comment = "link parent WIT"
                    }
                }
            });
            var createResult = workitemClient.CreateWorkItemAsync(patchDocument, projectName, "task").Result;

You may use this example (just change Bug to Task): https://www.visualstudio.com/en-us/docs/integrate/api/wit/samples#create-bug 您可以使用此示例(只需将Bug更改为Task): https : //www.visualstudio.com/zh-cn/docs/integrate/api/wit/samples#create-bug

Also you have to add information about link: https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#with-a-work-item-link in your case: 另外,您还必须添加有关链接的信息:在您的情况下, https : //www.visualstudio.com/zh-cn/docs/integrate/api/wit/work-items#with-a-work-item-link

patchDocument[4] = new { op = "add", path = "/relations/-", value = new { rel = "System.LinkTypes.Hierarchy-Reverse", url = " https://accountname.visualstudio.com/_apis/wit/workitems/ {USERSTORY_ID}"} }; patchDocument [4] = new {op =“ add”,path =“ / relations /-”,value = new {rel =“ System.LinkTypes.Hierarchy-Reverse”,url =“ https://accountname.visualstudio.com / _apis / wit / workitems / {USERSTORY_ID}“}};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用c#中的Web / REST API在salesforce中创建用户? - How to create user in salesforce using Web/REST API from c#? 使用c#的TFS API - TFS API using c# 如何使用Rest API为服务中的史诗级或用户故事中的引用字段设置值 - How to set a value to reference field in service now epic or user story using rest api Rally C#:是否可以创建带有附件的新用户故事? (避免查询用户故事参考) - Rally C#: Is it possible to create a new user story along with an attachment? (Avoiding to query for the user-story reference) 如何在C#中使用Tasks.Parallel停止现有任务 - How to stop an existing task using Tasks.Parallel in c# 如何使用C#中的Rally Rest API在一个特定的工作空间下检索所有缺陷? - How to retrieve all the defects under one particular workspace using the Rally Rest API's in C#? 如何使用Rally REST .NET将附件添加到用户故事 - How to Add an Attachment to a User Story using Rally REST .NET 如何使用Rally Api和.NET在特定工作区和项目中创建用户素材 - How to create a User Story in a certain Workspace and Project using Rally Api and .NET 通过TFS API REST或TFS SERVER API C#在TFS 2017中添加团队管理员 - Add team's administrator in TFS 2017 by TFS API REST or TFS SERVER API C# 如何使用C#在Window OS中的系统NT Authority\System下创建新用户 - How to Create New User under NT Authority\System the System in Window OS using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM