Skip to content

Instantly share code, notes, and snippets.

@xagronaut
Created January 16, 2015 00:06
Show Gist options
  • Save xagronaut/fa26a3c26272b1257758 to your computer and use it in GitHub Desktop.
Save xagronaut/fa26a3c26272b1257758 to your computer and use it in GitHub Desktop.
A short self-contained JavaScript snippet (IIFE) to apply a tag to multiple TFS Work Items through the TFS Web Access interface. If you don't have a version of TFS that allows bulk application of tags, this can help.
// Author: Jeffrey A. Miller (@xagronaut), 01/15/2015
// License: Apache 2.0
//
// Description: Apply a custom tag to multiple TFS Work Items systematically
//
// Notes:
// * Navigate to a TFS query page [YourTfsServer]:8080/tfs/[TfsCollection]/[TfsProject]/_workItems
// * Identify the Work Item IDs you want to update and edit the array at the end of this code snippet
// * This code should be executed in your browser's script console (tested in Chrome)
//
// options:
// tagName - the tag you want to apply; be sure it matches any existing spellings correctly if it is already in the system
// workItemIds - the list (array) of Work Item Ids to affect
// delayTime - how long to wait between browser operations (in case there is latency in loading/saving the Work Items)
//
(function(options) {
options = options || { tagName: '', workItemIds: [] };
var updateCount = 0;
var addTags;
addTags = function(id) {
if(id) {
window.location.hash = '#_a=edit&id=' + id + '&triage=true';
window.setTimeout(function() {
$("div.tfs-tags:visible li.tags-add-button .tag-box").click();
$("div.tfs-tags:visible input.tags-input").focus().val(options.tagName).blur();
$("li[command='save-work-item']:visible").click();
updateCount++;
var nextId = options.workItemIds.pop();
(nextId && window.setTimeout(function() { addTags(nextId); }, options.delayTime)) || alert('Done - ' + updateCount + ' updated.');
}, options.delayTime);
}
};
addTags(options.workItemIds.pop());
}({
tagName: 'Custom Tag', // adjust this to the tag you want to apply -- make sure you spell it correctly, especially if it is an existing tag, to prevent tag 'fragmenting'
workItemIds: [5001,5013,8002,8063], // adjust this list of TFS Work Item IDs to include the ones that need the tag added
delayTime: 2500 // how long to wait time between browser operations (in milliseconds)
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment