7

I am writing a utility to read all the defects out of a legacy bug tracking system, and import them into TFS (2008/2010). I am using the TFS API to create new WorkItems, set their fields, and then save them. However I am unable to modify the "Created By" and "Created Date" fields, as these are set by the system. (and there are other fields too which I would like to be able to force values for, such as setting the submitter to be someone who is not a valid TFS user)

// these fail with "The value for the field 'Created By' cannot be changed."
defectWorkItem.Fields["Created By"].Value = defect.Submitter;
defectWorkItem.Fields["Created Date"].Value = defect.SubmitDate;

Obviously if I can't set these fields, I'll end up with all the legacy bugs looking like they were created on the same date by the same person.

Is there a way I can use the API but force through changes to fields that are normally protected? I have looked into accessing the TFS database tables directly, but the schema looks complicated and I think it would be quite risky to attempt to modify the data there myself.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Mark Heath
  • 48,273
  • 29
  • 137
  • 194

2 Answers2

8

You are allowed to set the Created Date and Created By fields if you are a service account and you turn on the bypass rules feature.

You can choose to bypass the rules when you create an instance of WorkItemStore class by using this flag: WorkItemStoreFlags.BypassRules.

Please note that you are allowed to set these fields only for the first revision of the work items.

Littm
  • 4,923
  • 4
  • 30
  • 38
  • 1
    thanks, this sounds exactly what I need. I'll try it out and mark it as answer if I can get it working – Mark Heath Sep 30 '12 at 06:21
  • Do you know if this flag is new with TFS 2012? It isn't in the previous version of the library. – Mark Heath Oct 04 '12 at 14:09
  • I've been trying this out and it is a little strange. First, you can't set these fields on the first save, only subsequent saves. Second, it won't let me change System.CreatedBy, even though I can change System.CreatedDate and Microsoft.VSTS.Common.ActivatedDate with this technique. – Mark Heath Oct 04 '12 at 15:25
  • `Created By` cant be changed by this way after first revision as you said. (Error:TF26194: The value for the field 'Created By' cannot be changed) Any solution for this? – Reza May 11 '14 at 14:09
1

Just a suggestion: Insert this text at the start of the description of a work item when migrating:

  • Migrated from System XXX
  • Original creation date: 1/1 2012
  • Original created by: John Doe
Morten Frederiksen
  • 5,114
  • 1
  • 40
  • 72
  • yes, that's what I'll do if I can't modify the created dates at all, but it will mean that people can't use the queries they are used to from the old system – Mark Heath Sep 28 '12 at 14:54