In TFS 2013 how one project work items could be moved to other project
Jun 10, 2020 02:28 PM|bharatveer4.gurjar@gmail.com|LINK
Hi All,
Recently i have been given to develop a functionality in C# where i need to create. In which in TFS 2013 one team project work item to be moved to another team project.
svn-mosx-wxe01\TFS2010 (servr URL). both project are under same server as you can see below for understanding.
Project1
Project2
Now Project1 work items could be moved to Project2. Is it possible that Project1 work items AreaPath and ItirationPath also should be created or we need to use Project2 Area Path and Itiration Path to copy the work item from the Project1.
On Azure DevOps you need to select the existing AreaPath and IterationPath to which you want to assign those moved items. It you really neeed the old one you can always create jsut the area and iteration by hand before moving items.
Re: In TFS 2013 how one project work items could be moved to other project
Jun 11, 2020 10:56 AM|bharatveer4.gurjar@gmail.com|LINK
First of all thank you so much for your consideration because i am trying but could not make it but thank you so much again.
So you mean If i have project 1 work item to be moved Project 2 then i need to use already existing AreaPath and IterationPath in project 2 for the work item that are going to be moved here.
OR
I need to create Manually in project 2 the same Area Path Or Iteration Path that was used in Project 1(You can correct me if i am wrong).
Is there any way that pragmatically required AreaPath or ItirationPath could be created in Project 2 and then items are moved to them.
I would be so thankful if you could provide me code snippet for it.
I have this code for now is working with in same project from IterationPath1 to IterationPath2 as an example. Could you please change it so that it could work from one project to other project for moving the items. Many many thanks to you Sir.
internal int Copy(string TeamProjecct, string FromIterationPath, string ToIterationPath, ref CheckForNewDlls.CircularProgressBar circularProgressBar1)
{
int iCopyCount = 0;
var targetWorkItemStore = GetTargetWorkItemStore();
string sQuery = string.Format(WiqlAll, FromIterationPath);
var targetWorkItems = targetWorkItemStore.Query(sQuery);
Dictionary<int, int> NewIds = new Dictionary<int, int>();
Dictionary<int, WorkItem> NewWorkItems = new Dictionary<int, WorkItem>();
I can't really test this code. I assume you do have an exception when this code runs? It's far better to always tell which exception you have and on which line it happens. Given the previous discussion I assume that the AreaPath and/or IterationPath is
not changed to a valid value for the target project ?
I would have to see if a blank value is always valid but it might be a first step.
Always discuss directly your issue. At first it sounded like some kind of requirement issue ie what is the "best thing" to do. It always depend on your own situation (and so Azure DevOps allows the user to select an iteration path, area path when moving
items accross projects, if doing something similar you'll just have the same once moved ato Azure DevOps).
Re: In TFS 2013 how one project work items could be moved to other project
Jun 16, 2020 03:57 AM|bharatveer4.gurjar@gmail.com|LINK
Hi PatriceSc,
First of all thank you very much for your response.
I am working in TFS 2010 sorry for last time referring wrong version. In which I need to Move one project Work item To Other Project with in
same server or you can say TFS URL like
http://sXp-XXX-wXe01:8080/tfs. Its a one time activity to move the work item from Project 1 to project 2.
If you can provide me the code for doing it that is fine.
Or If you can provide me some other approach like API or by Manual steps in TFS that is also fine. Because Client want Item must be moved no matter
It is by Code Or By Some Other Approach.
In Above code i face the error "TF237124: Work Item is not ready to save" on targetWorkItem.Save(); line.
targetWorkItem.IterationPath = "z BP Test\\TFSItemCopy2"; on this line "z BP Test" is other project and "TFSItemCopy2" is predefined Iteration in this project where i want to move my work Item.
I am using this below mentioned query to get the Work Item From the "KOMLIS" project and by The workItemID that is [System.Id] in the query.
None
0 Points
13 Posts
In TFS 2013 how one project work items could be moved to other project
Jun 10, 2020 02:28 PM|bharatveer4.gurjar@gmail.com|LINK
Hi All,
Recently i have been given to develop a functionality in C# where i need to create. In which in TFS 2013 one team project work item to be moved to another team project.
svn-mosx-wxe01\TFS2010 (servr URL). both project are under same server as you can see below for understanding.
Project1
Project2
Now Project1 work items could be moved to Project2. Is it possible that Project1 work items AreaPath and ItirationPath also should be created or we need to use Project2 Area Path and Itiration Path to copy the work item from the Project1.
Thank you so much.
All-Star
48530 Points
18077 Posts
Re: In TFS 2013 how one project work items could be moved to other project
Jun 10, 2020 02:50 PM|PatriceSc|LINK
Hi,
On Azure DevOps you need to select the existing AreaPath and IterationPath to which you want to assign those moved items. It you really neeed the old one you can always create jsut the area and iteration by hand before moving items.
None
0 Points
13 Posts
Re: In TFS 2013 how one project work items could be moved to other project
Jun 11, 2020 10:56 AM|bharatveer4.gurjar@gmail.com|LINK
First of all thank you so much for your consideration because i am trying but could not make it but thank you so much again.
So you mean If i have project 1 work item to be moved Project 2 then i need to use already existing AreaPath and IterationPath in project 2 for the work item that are going to be moved here.
OR
I need to create Manually in project 2 the same Area Path Or Iteration Path that was used in Project 1(You can correct me if i am wrong).
I have this code for now is working with in same project from IterationPath1 to IterationPath2 as an example. Could you please change it so that it could work from one project to other project for moving the items. Many many thanks to you Sir.
internal int Copy(string TeamProjecct, string FromIterationPath, string ToIterationPath, ref CheckForNewDlls.CircularProgressBar circularProgressBar1)
{
int iCopyCount = 0;
var targetWorkItemStore = GetTargetWorkItemStore();
string sQuery = string.Format(WiqlAll, FromIterationPath);
var targetWorkItems = targetWorkItemStore.Query(sQuery);
Dictionary<int, int> NewIds = new Dictionary<int, int>();
Dictionary<int, WorkItem> NewWorkItems = new Dictionary<int, WorkItem>();
foreach (WorkItem SourceWorkItem in targetWorkItems)
{
circularProgressBar1.Refresh();
WorkItem targetWorkItem = SourceWorkItem.Copy();
iCopyCount++;
if (ToIterationPath != TeamProjecct + "\\")
{
targetWorkItem.IterationPath = ToIterationPath;
}
if (SourceWorkItem.Fields["System.AssignedTo"].Value.ToString() == "")
{
targetWorkItem.Fields["System.AssignedTo"].Value = "";
}
targetWorkItem.Save();
NewIds.Add(SourceWorkItem.Id, targetWorkItem.Id);
NewWorkItems.Add(targetWorkItem.Id, targetWorkItem);
if (SourceWorkItem.AttachedFileCount > 0)
{
circularProgressBar1.Refresh();
circularProgressBar1.Refresh();
ProcessAttachments(SourceWorkItem, targetWorkItem);
try
{
targetWorkItem.Save(SaveFlags.None);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(string.Format(" [saved: {0}]", targetWorkItem.Id));
Console.ResetColor();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}
NewWorkItems = NewWorkItems.Reverse().ToDictionary(x => x.Key, x => x.Value);
foreach (WorkItem wi in NewWorkItems.Values)
{
circularProgressBar1.Refresh();
WorkItemLink ParentLink = null;
List<WorkItemLink> RelatedLinks = new List<WorkItemLink>();
foreach (WorkItemLink wil in wi.WorkItemLinks)
{
if (wil.LinkTypeEnd.Name == "Parent")
{
ParentLink = wil;
}
if (wil.LinkTypeEnd.Name == "Related")
{
WorkItem linkedWorkItem = targetWorkItemStore.GetWorkItem(wil.TargetId);
wi.WorkItemLinks.Remove(wil);
wi.Save(SaveFlags.MergeLinks);
break;
}
}
if (ParentLink != null)
{
WorkItemLink NewParent = new WorkItemLink(ParentLink.LinkTypeEnd);
NewParent.SourceId = ParentLink.SourceId;
NewParent.TargetId = NewIds[ParentLink.TargetId];
wi.WorkItemLinks.Remove(ParentLink);
wi.WorkItemLinks.Add(NewParent);
}
circularProgressBar1.Refresh();
wi.Save();
}
return iCopyCount;
}
Thank you so much.
None
0 Points
13 Posts
Re: In TFS 2013 how one project work items could be moved to other project
Jun 15, 2020 04:17 AM|bharatveer4.gurjar@gmail.com|LINK
Hi Patrice
Please could u update the code i sent in message trail.
Regards,
Bharat Veer
All-Star
48530 Points
18077 Posts
Re: In TFS 2013 how one project work items could be moved to other project
Jun 15, 2020 09:55 AM|PatriceSc|LINK
I can't really test this code. I assume you do have an exception when this code runs? It's far better to always tell which exception you have and on which line it happens. Given the previous discussion I assume that the AreaPath and/or IterationPath is not changed to a valid value for the target project ?
I would have to see if a blank value is always valid but it might be a first step.
Always discuss directly your issue. At first it sounded like some kind of requirement issue ie what is the "best thing" to do. It always depend on your own situation (and so Azure DevOps allows the user to select an iteration path, area path when moving items accross projects, if doing something similar you'll just have the same once moved ato Azure DevOps).
None
0 Points
13 Posts
Re: In TFS 2013 how one project work items could be moved to other project
Jun 16, 2020 03:57 AM|bharatveer4.gurjar@gmail.com|LINK
Hi PatriceSc,
First of all thank you very much for your response.
I am working in TFS 2010 sorry for last time referring wrong version. In which I need to Move one project Work item To Other Project with in
same server or you can say TFS URL like http://sXp-XXX-wXe01:8080/tfs. Its a one time activity to move the work item from Project 1 to project 2.
If you can provide me the code for doing it that is fine.
Or If you can provide me some other approach like API or by Manual steps in TFS that is also fine. Because Client want Item must be moved no matter
It is by Code Or By Some Other Approach.
In Above code i face the error "TF237124: Work Item is not ready to save" on targetWorkItem.Save(); line.
targetWorkItem.IterationPath = "z BP Test\\TFSItemCopy2"; on this line "z BP Test" is other project and "TFSItemCopy2" is predefined Iteration in this project where i want to move my work Item.
I am using this below mentioned query to get the Work Item From the "KOMLIS" project and by The workItemID that is [System.Id] in the query.
private const string WiqlAll = "SELECT [System.Id], [System.State], [System.Title], [System.AssignedTo], [System.WorkItemType], [Microsoft.VSTS.Common.Priority], " +
"[System.IterationPath], [System.History], [System.Description] " +
"FROM WorkItems WHERE [System.TeamProject] ='KOMLIS' AND " +
"[System.Id] = '23582' " +"ORDER BY [System.Id]";
If you can provide me your email ID i can send you whole code. Thank you so much.
This code is working fine for the same project.