问题
I have a WebApplication that creates and changes WorkItems through the API. I want the "ChangedBy" field be set to a specific string-value. This worked well with TFS 2013. After upgrading to TFS 2015 my value is ignored and ChangedBy is always set to the identity of the user that I use for connecting to the TFS.
This is my code:
//Set some values on the WorkItem
item.Fields["ChangedBy"].Value = "MyUserName";
item.Save();
Is there a way to enforce the behaviour like it was in TFS 2013?
回答1:
According to this blog, by default, the Changed By field is one of the non-editable fields (set by the system). In order to modify it, you need to use work with WorkItemStore object in BypassRule mode. Bypass Rule allow you to modify the work item fields without any restrictions, so you can change the Changed By field.
Define your code as:
TfsTeamProjectCollection tfctc = new TfsTeamProjectCollection(new Uri("http://servername:8080/tfs/DefaultCollection"));
WorkItemStore workItemStore = new WorkItemStore(tfctc, WorkItemStoreFlags.BypassRules);
WorkItem workItem = workItemStore.GetWorkItem(workitemid);
string changedBy = (string)workItem.Fields["Changed By"].Value;
workItem.Fields["Changed By"].Value = "User Name";
来源:https://stackoverflow.com/questions/32800597/tfs-2015-api-ignores-changedby