Programatically forcing field values for a TFS WorkItem

无人久伴 提交于 2019-12-06 00:06:10

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/12640672/programatically-forcing-field-values-for-a-tfs-workitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!