3

I use VSTS and tfs aggregator to update parent fields when I have some changes in work items, and every things work fine. Now I want to update parent field when I delete the work Item. and I get the error:

    Exception encountered processing notification: TF26198: 
The work item does not exist, or you do not have permission to access it. 
Stack Trace:   
at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.LoadWorkItemFromRowSetInternal(Int32 rev, Nullable`1 asof, IWorkItemRowSets witem)
at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem..ctor(WorkItemStore store, Int32 id)
at Aggregator.Core.Facade.WorkItemRepository.GetWorkItem(Int32 workItemId)
at Aggregator.Core.EventProcessor.ProcessEvent(IRequestContext requestContext, INotification notification)
at Aggregator.WebHooks.Controllers.WorkItemController.Post(JObject payload)

It makes sense when I delete the workItem, there is no work item I could access via it to parent, But is there any way to get the deleted workItem's parent? any idea?

Saeid
  • 13,224
  • 32
  • 107
  • 173

2 Answers2

2

There is no simple answer to this.

We added support for the deleted event at some point, but Aggregator receives the event, after TFS has marked the work item as deleted. The API we use filters out those objects IIRC. The only useful piece of information you have is the ID of the deleted work item. Using PreviousRevision you might be able going back in time, but I haven't tried.

Source code is available and PR are always welcomed.

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
1

Update: You can't do this.

The error is very clear:

The work item does not exist, or you do not have permission to access it.

When you delete the work item through command, all information is also deleted. This permanently remove work items from the data store. A permanent delete means all information in the WIT data store is deleted and cannot be restored nor reactivated. You definitely could not query and update the deleted Work Item's parent.

Even if the work item exist "somewhere", then you don't have permission to open the work item, and also you can't query information about it. It's a bit of chicken/egg. Take a look at this similar question: TFS API: How to check if a work item has been deleted or is non existent on the TFS Server? (not if it is accessible)

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • I don't want to restore workItem, I want to update the parent when the workitem deleted (or exactly before delete) – Saeid Dec 13 '17 at 14:15
  • @Saeid The error is very clear, `The work item does not exist, or you do not have permission to access it.`, when you delete the work item through command, all information is deleted. Even if the work item exist somewhere, then you don't have permission to open the work item, and also you can't query information about it. It's a bit of chicken/egg. See my update answer. Also take a look at this similar question: https://stackoverflow.com/questions/14302732/tfs-api-how-to-check-if-a-work-item-has-been-deleted-or-is-non-existent-on-the – PatrickLu-MSFT Dec 13 '17 at 15:29
  • I understand, Steel I need to update parent. I said that it make sense that the workItem is not exist when deleted, I have a Remaining work on parent and when the work Item deleted I need to update parent – Saeid Dec 13 '17 at 16:55
  • 1
    @PatrickLu-MSFT I think the OP refers to _soft delete_, when work items are sent to the Recycle bin. – Giulio Vian Dec 14 '17 at 13:25
  • Hi @Saeid, First this could not be achieved through out of the box features in TFS side. And even with 3-party extension, according to Giulio's reply, it's also not support, you may have to customize it. If you want do this, try to follow Giulio's suggestion, use `PreviousRevision` back and obtain the parent, then update related field. – PatrickLu-MSFT Dec 14 '17 at 14:42