2017-04-13 44 views
1

我正在使用Microsoft.TeamFoundation.WorkItemTracking.WebApi並試圖從項目中添加和刪除工作項目鏈接。我如何使用TFS WebApi刪除工作項目

我打電話

workItemTrackingHttpClient.UpdateWorkItemAsync(jsonPatchDocument, Id); 

和我JsonPatchDocument看起來是這樣的。

[ 
    { 
    "op": 1, 
    "Path": "/relations/-", 
    "From": null, 
    "Value": { 
     "Rel": "System.LinkTypes.Dependency-Forward", 
     "Url": "https://[server]/tfs/DefaultCollection/_apis/wit/workItems/[id]" 
    } 
    } 
] 

當我使用「OP」:0更新(添加)它工作正常,但我不能刪除制定出正確的形式。

我得到類似

VssServiceException

刪除不支持插入一個錯誤。 Microsoft.VisualStudio.Services.WebApi -2146232832

任何人有任何想法,請。

+0

關於下面的方法,你還有其他問題嗎? –

+0

謝謝你幫我解決了這個問題。我只需要加載現有的工作項並遍歷關係以找到我需要刪除的索引。它有點低效,但它的工作原理。 – LepardUK

回答

2

要刪除一個鏈接,JsonPatchDocument不像插入,有必要提供「值」。

它是這樣的:

[ 
    { 
    "op": "test", 
    "path": "/rev", 
    "value": 3 
    }, 
    { 
    "op": "remove", 
    "path": "/relations/0" 
    } 
] 

刪除鏈接,你需要指向使用"relations/Id"除去其中的鏈接。 Id從0開始。

如需更多歸納,請參閱official document