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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With