I have created TFS 2012 Serverside event handler for enforcing code review policy. I am able to create work item for Code review Request and response. But After completed review process, when I am going to check in reviewed code unable to see reviewed work item in Related Work item section in Team explorer window in visual studio 2013. below are my code,
var workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
WorkItemType wiType = workItemStore.Projects[0].WorkItemTypes["Code Review Request"];
WorkItem workItem = new WorkItem(wiType);
workItem.Fields["System.AssignedTo"].Value = "XXXXXX";
//ev.ChangesetOwner.DisplayName;
workItem.Fields["Microsoft.VSTS.CodeReview.ContextType"].Value = "Shelveset";
workItem.Fields["Microsoft.VSTS.CodeReview.Context"].Value = shelveset.Name;
workItem.Fields["Microsoft.VSTS.CodeReview.ContextOwner"].Value = shelveset.OwnerName;
workItem.Fields["System.AreaPath"].Value = project.Name;
workItem.Fields["System.IterationPath"].Value = project.Name;
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
workItem.Fields["System.Description"].Value = "Code Review Request ";
workItem.Fields["System.Title"].Value = "Code Review Request " + System.DateTime.Now.ToString();
var invalidFields = workItem.Validate();
if (workItem.IsValid())
workItem.Save();
var responseId = workItem.Id;
var type = workItemStore.Projects[0].WorkItemTypes["Code Review Response"];
workItem = new WorkItem(type);
workItem.Fields["System.AssignedTo"].Value = "xxxxxxxx";
workItem.Fields["System.AreaPath"].Value = project.Name;
workItem.Fields["System.IterationPath"].Value = project.Name;
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
workItem.Fields["Microsoft.VSTS.Common.ReviewedBy"].Value = "xxxxxxxx";
workItem.Fields["System.Title"].Value = "Code Review Response " + System.DateTime.Now.ToString();
WorkItemLinkTypeEnd linkTypeEnd = workItemStore.WorkItemLinkTypes.LinkTypeEnds["Parent"];
workItem.Links.Add(new RelatedLink(linkTypeEnd, responseId));
if (workItem.IsValid())
workItem.Save();