Wednesday, January 24, 2018

How to Add TFS Stories Programmatically Through a URL

You can add TFS stories and features through a browser's URL.  This complements the Template process and is simpler than the real API which should be used for real work.

Here's an example URL to create a task, assign it to person, and enter a description:


https://tfs.example.com/tfs/TopLevel/MediumLevel/Project/_workItems/create/Task?%5BSystem.AssignedTo%5D=Wiley+Coyote&%5BSystem.Description%5D=%3Cp%3EExample+Description+Text.%3C%2Fp%3E

This looks like garbage because it is html encoded.  Plain text, courtesy of www.utilities-online.info/urlencode/  would be:

https://tfs.example.com/tfs/TopLevel/MediumLevel/Project/_workItems/create/Task?[System.AssignedTo]=Wiley+Coyote&[System.Description]=Example+Description+Text.

obkb.com has a quick hex code guide.

This will create a task, but not save it.

Here is a non-trivial example, unescaped, and put on multiple lines for clarity:

https://tfs.example.com/tfs/TopLevel/MediumLevel/Project/_workItems/create/User Story?[System.AssignedTo]=Wiley+Coyote
&[Acme.ENABLE.TRAP.ID]=797
&[Acme.ENABLE.PROJ.ID]=777
&[Microsoft.VSTS.Common.ValueArea]=Business
&[Microsoft.VSTS.Common.AcceptanceCriteria]=The Roadrunner is captured.
&[System.Tags]=Food
&[System.AreaPath]=Plans\Trap
&[System.Title]=Giant Mouse Trap to Catch Roadrunner
&[System.Description]=Order giant mouse trap
Place bird seed in trap
wait for roadrunner to get caught

The tricky part is finding the names of the element you want to add.  Fortunately, you can get a Visual Studio plugin which will allow you to see the standard element names and your companies custom names.

You can download the TFS Process Template Editor here.
It will install into VS2017 under the Tools menu.  Select the Process Editor and the "Work Item Field Explorer".


This will display a list of the field names including your custom defined ones:

This method works will for small tasks, but for larger tasks, use the API.

1 comment:

Anonymous said...

Wow, just realized I could contact you through here. Pretty cheeky on my part, but I sent you an email through the Mayan periodic website at MayanPeriodic@gmail.com. Not sure which message you will see first, but I would ask if you could read my email I have sent you.