The workitem creation using TFS is well known. Here I am just sharing the code snippet which retrieves the URL for a newly created workitem. The URL returned is same as the URL generated when "Send to Outlook" button is clicked in TFS against a workitem.
WorkItemStore _wiStore = new WorkItemStore(tfsServer); //tfsServer is your TFS server URL
var project = _wiStore.Projects[<bugs project>]; //Put your project name containing bug type workitems
WorkItemType workItemType = project.WorkItemTypes["Bug"]; //Create new bug workitemtype
WorkItem _workItem = new WorkItem(workItemType); //Create bug workitem object
TswaClientHyperlinkService _hyperlinkService = tfsServer.GetService<TswaClientHyperlinkService>(); //Initialize TFS' hyperlink service
_workItem.Fields["Title"].Value = title;
_workItem.Fields["Area Path"].Value = areaPath;
_workItem.Fields["Iteration Path"].Value = iteration;
...
...
//initialize other WorkItem fields
...
...
var validationErrors = _workItem.Validate();
if (validationErrors.Count == 0)
{
_workItem.Save();
string bugUrl = _hyperlinkService.GetArtifactViewerUrl(_workItem.Uri).ToString(); //The URL we are looking for
}
Hope this helps.
WorkItemStore _wiStore = new WorkItemStore(tfsServer); //tfsServer is your TFS server URL
var project = _wiStore.Projects[<bugs project>]; //Put your project name containing bug type workitems
WorkItemType workItemType = project.WorkItemTypes["Bug"]; //Create new bug workitemtype
WorkItem _workItem = new WorkItem(workItemType); //Create bug workitem object
TswaClientHyperlinkService _hyperlinkService = tfsServer.GetService<TswaClientHyperlinkService>(); //Initialize TFS' hyperlink service
_workItem.Fields["Title"].Value = title;
_workItem.Fields["Area Path"].Value = areaPath;
_workItem.Fields["Iteration Path"].Value = iteration;
...
...
//initialize other WorkItem fields
...
...
var validationErrors = _workItem.Validate();
if (validationErrors.Count == 0)
{
_workItem.Save();
string bugUrl = _hyperlinkService.GetArtifactViewerUrl(_workItem.Uri).ToString(); //The URL we are looking for
}
Hope this helps.
Thank you, so much, A!
ReplyDeleteI found this just when I needed it :)
Cheers,
V