Как создать / обновить рабочий элемент с отношением «родитель-потомок» в C # с помощью API Devure в Azure в Devops в Azure - PullRequest
0 голосов
/ 30 января 2019

Я пытаюсь создать / обновить рабочий элемент в devop Azure с помощью API.Я могу создать / обновить элемент, если он не имеет никакого отношения.Но если я укажу отношение, например parent-child, то получаю сообщение об ошибке ниже:

TF401349: произошла непредвиденная ошибка, проверьте ваш запрос и повторите попытку.

Я использую JsonPatchDocument для создания/ обновить рабочий элемент.Пример ниже:

class Example
{
    JsonPatchOperation AddRelationship(JsonPatchDocument doc, string rel, WorkItem linkedItem, bool isNew, int index)
    {
        //update link
        if (!isNew)
        {
            return new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/relations/" + index,
                Value = new { rel, url = linkedItem.Url, attributes = new { comment = "comment while update" } }
            };
        }
        else
            return new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/relations/-",
                Value = new { rel, url = linkedItem.Url, attributes = new { comment = "Comment while creating item" } }
            };
    }

    void Save()
    {
        // some code
        doc.Add(AddRelationship(doc, "System.LinkTypes.Hierarchy-Forward", item, isNew, index++));

        var workItem = isNew
                     ? witClient.CreateWorkItemAsync(doc, Vsts.Project, issueType, bypassRules: true, validateOnly: Mode == ProcessingMode.ReadOnly).Result
                     : witClient.UpdateWorkItemAsync(doc, existingWorkItemId.Value, bypassRules: true, validateOnly: Mode == ProcessingMode.ReadOnly).Result;

    }
}

}

Спасибо.

1 Ответ

0 голосов
/ 30 января 2019

Я не вижу определения "rel" в вашем примере.Примерно так:

patchDocument.Add(new JsonPatchOperation()
{
    Operation = Operation.Add,
    Path = "/relations/-",
    Value = new {
        rel = "System.LinkTypes.Hierarchy-Forward",
        url = RelUrl,
        attributes = new
        {
            comment = "Comment for the link"
        }
    }
});

Может быть, ваш код должен быть таким:

JsonPatchOperation AddRelationship(JsonPatchDocument doc, string relname, WorkItem linkedItem, bool isNew, int index)
{
    //update link
    if (!isNew)
    {
        return new JsonPatchOperation()
        {
            Operation = Operation.Replace,
            Path = "/relations/" + index + "/attributes/comment",
            Value = "comment while update" 
        };
    }
    else
        return new JsonPatchOperation()
        {
            Operation = Operation.Add,
            Path = "/relations/-",
            Value = new { rel = relname, url = linkedItem.Url, attributes = new { comment = "Comment while creating item" } }
        };
}
...