locked
Updating the Reason field after Workflow Changes RRS feed

  • Question

  • What options do I have for updating the Reason field after making modifications to workflow?  We changed some of the values of Reason and would like to update work item types with older values in them.  Ideally I don't have to have to transition work items in and out of states to change the reason field.

    Saturday, July 30, 2011 3:41 AM

Answers

  • You probably need to change status twise, you could use the tfs api to create your own tool to do the update like this  

     WorkItemStore wiStore = new WorkItemStore(TFSCollectionUrl);
    
      WorkItemCollection wiLst = wiStore.Query(
        " SELECT [System.Id], [System.AssignedTo], [System.Title] " +
        " FROM WorkItems " +
        " WHERE [System.Id] = 1579 ORDER BY [System.WorkItemType], [System.Id]");
    
      foreach (WorkItem itm in wiLst)
      {
       itm.Open();
       itm.State="YourCustomStateForEditingofWorkflow" ;
       itm.Reason="YourCustomREASONforEditingofWorkflow" ;
    
       itm.Save();
       itm.State="YourOrginalState" ;
       itm.Reason="YourNewReason" ;
       itm.Save();
      }
    

     

     

     

     



    Sunday, July 31, 2011 12:08 AM

All replies

  • You probably need to change status twise, you could use the tfs api to create your own tool to do the update like this  

     WorkItemStore wiStore = new WorkItemStore(TFSCollectionUrl);
    
      WorkItemCollection wiLst = wiStore.Query(
        " SELECT [System.Id], [System.AssignedTo], [System.Title] " +
        " FROM WorkItems " +
        " WHERE [System.Id] = 1579 ORDER BY [System.WorkItemType], [System.Id]");
    
      foreach (WorkItem itm in wiLst)
      {
       itm.Open();
       itm.State="YourCustomStateForEditingofWorkflow" ;
       itm.Reason="YourCustomREASONforEditingofWorkflow" ;
    
       itm.Save();
       itm.State="YourOrginalState" ;
       itm.Reason="YourNewReason" ;
       itm.Save();
      }
    

     

     

     

     



    Sunday, July 31, 2011 12:08 AM
  • Here's the PowerShell equivalent I ended up using:

    [Reflection.Assembly]::Load("Microsoft.TeamFoundation.WorkItemTracking.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | out-null;
     
    $tfsUrl = new-object Uri("http://myserver:8080/tfs/DefaultCollection");
    $projectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUrl);
    $workItemStore = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore($projectCollection);
     
    $parameters = New-Object 'System.Collections.Generic.Dictionary[string,string]';
    $parameters.Add("TeamProject", "MyProject");
    $parameters.Add("WorkItemType", "Task");
    $parameters.Add("State", "Active");
    $parameters.Add("Reason", "New");
    $workItems = $workItemStore.Query("SELECT [System.Id], [System.AssignedTo], [System.Title]
                      FROM  WorkItems
                      WHERE [System.WorkItemType] = @WorkItemType AND
                         [System.State] = @State AND
                         [System.Reason] = @Reason AND
                         [System.TeamProject] = @TeamProject
                      ORDER BY [System.Id]", $parameters);
    Write-Host "Found $($workItems.Count) work items";
     
    foreach ($workItem in $workItems)
    {
      Write-Host "Processing $($workItem.Id)";
      $workItem.Open();
    	
      $workItem.State = "Active";
      $workItem.Reason = "In Progress";
      $workItem.Save();
      
      $workItem.State = "Closed";
      $workItem.Reason = "Done";
      $workItem.Save();  
    }
    


    Tuesday, August 9, 2011 1:20 AM