TFS 2015 API ignores ChangedBy

蓝咒 提交于 2019-12-11 21:13:59

问题


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

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