Using variables into TFS work item definitions - tfs

I currently have a TFS process template using a Bug Work Item type that contains the "Found In" and "Integration Build" fields.
They are defined like this in the work item definition XML file :
<FIELD name="Integration Build" refname="Microsoft.VSTS.Build.IntegrationBuild" type="String" reportable="dimension">
<HELPTEXT>The build in which the bug was fixed</HELPTEXT>
<SUGGESTEDVALUES expanditems="true">
<LISTITEM value="<None>" />
</SUGGESTEDVALUES>
</FIELD>
<FIELD name="Found In" refname="Microsoft.VSTS.Build.FoundIn" type="String" reportable="dimension">
<HELPTEXT>The build in which the bug was found</HELPTEXT>
<SUGGESTEDVALUES expanditems="true">
<LISTITEM value="<None>" />
</SUGGESTEDVALUES>
<REQUIRED />
</FIELD>
I wanted to use the auto-populated builds global list so I added the following lines as suggested on msdn :
<SUGGESTEDVALUES expanditems="true" filteritems="excludegroups">
<GLOBALLIST name="Builds - ProjectXYZ" />
</SUGGESTEDVALUES>
But I would like to share the same work item definition for ALL our projects. So my question is really simple, is there a way to replace "ProjectXYZ" by a variable that contains the name of the project that is using the work item definition ?
Basically this is what I would like :
<FIELD name="Found In" refname="Microsoft.VSTS.Build.FoundIn" type="String" reportable="dimension">
<HELPTEXT>The build in which the bug was found</HELPTEXT>
<SUGGESTEDVALUES expanditems="true">
<LISTITEM value="<None>" />
</SUGGESTEDVALUES>
<SUGGESTEDVALUES expanditems="true" filteritems="excludegroups">
<GLOBALLIST name="Builds - ${TeamProjectName}" />
</SUGGESTEDVALUES>
<REQUIRED />
</FIELD>

No it is not possible to use a variable there.
If you don't have many team projects you could use a when clause for each team project.
This would only work if you only had a few projects as It would get cumbersome otherwise.

Related

Defining VSTS Field only when Value of field is not Set

I have a need to set the value of a date field when the value of substate field changes only if no value already exists in the date field. Is it possible?
<FIELD refname="MyCorp.StateDate" name="Date Of Last State Change" type="DateTime">
<WHENCHANGED field="MyCorp.State">
<COPY from="clock" /> ** AND do this only of MyCorp.StateDate != Empty **
</WHENCHANGED>
</FIELD>
I read https://msdn.microsoft.com/en-us/library/ms194966.aspx but I am not able to find any way to implement what I need from the WIT language definition.
If you are using Visual Studio Team Services, add rules to work item is not supported now.
If you are using on-premise TFS, you can add field action in state transition, for example:
<TRANSITION from="New" to="Committed">
<REASONS>
<DEFAULTREASON value="Commitment made by the team" />
</REASONS>
<FIELDS>
<FIELD refname="starain.ScrumStarain.StateChageDate">
<WHEN field="starain.ScrumStarain.StateChageDate" value="">
<COPY from="clock" />
</WHEN>
</FIELD>
</FIELDS>
</TRANSITION>

TFS Transition Set System.AssignedTo from a string field

I am modifying a workflow in TFS 2013 and have bumped into a snag. Right now, when a developer completes their work and moves the work item into 'dev complete' I set the name of the developer moving the work item to a custom field as a string:
MYCOMPANY.Agile.Lean.CodeCompleteBy
<FIELD name="Code Completed By" refname="MYCOMPANY.Agile.Lean.CodeCompleteBy" type="String" reportable="dimension" syncnamechanges="true">
<ALLOWEXISTINGVALUE />
<HELPTEXT>The developer who wrote code related to this work item.</HELPTEXT>
</FIELD>
And here is the transition:
<TRANSITION from="Development in Progress" to="Code Review">
<REASONS>
<DEFAULTREASON value="Ready for Code Review" />
</REASONS>
<FIELDS>
<FIELD refname="System.AssignedTo">
<DEFAULT from="currentuser" />
</FIELD>
<FIELD refname="MYCOMPANY.Agile.Lean.CodeCompleteBy">
<DEFAULT from="currentuser" />
</FIELD>
</FIELDS>
</TRANSITION>
As the process continues the item eventually reaches QA. IF the QA person finds a problem and rejects the work then I have a transition to move the work item back into the 'Development in Progress' state. All of that works fine.
The Problem
I want to re-assign the work item, upon transition from QA in Progress back to Development in Progress, back to the original developer who did the work.
<TRANSITION from="QA in Progress" to="Development in Progress">
<REASONS>
<REASON value="Requirements Not Met" />
<REASON value="Rejected" />
<DEFAULTREASON value="Failed Testing" />
</REASONS>
<FIELDS>
<FIELD refname="System.AssignedTo">
<DEFAULT from="MYCOMPANY.Agile.Lean.CodeCompleteBy" />
</FIELD>
</FIELDS>
</TRANSITION>
Unfortunately, when I attempt to apply my new WIT transitions it throws the following error:
TF212019: Work item tracking schema validation error at row 931, column 24: The 'from' attribute is invalid - The value 'MYCOMPANY.Agile.Lean.CodeCompleteBy' is invalid according to its datatype 'http://schemas.microsoft.com/VisualStudio/2008/workitemtracking/typelib:CopyFrom' - The Enumeration constraint failed.
TF237070: Importing the definition failed. The definition you are trying to import did not validate against the schema. Edit the definition, then try to import it again.
I see that this is an Enumeration constraint issue, but I'm not familiar enough with TFS internal workings to know how to get around the problem.
Does anyone have a slick way of accomplishing what I am trying to do (even if I just need a completely new approach)? I may just be going down the wrong path altogether.
Thanks!
Instead of using the default which will simply try and set that as the value, try using the Copy rule.
Something like this:
<TRANSITION from="QA in Progress" to="Development in Progress">
<REASONS>
<REASON value="Requirements Not Met" />
<REASON value="Rejected" />
<DEFAULTREASON value="Failed Testing" />
</REASONS>
<FIELDS>
<FIELD refname="System.AssignedTo">
<COPY from="field" field="MYCOMPANY.Agile.Lean.CodeCompleteBy" />
</FIELD>
</FIELDS>
</TRANSITION>
Update the syntax like following:
<DEFAULT from="field" field="MYCOMPANY.Agile.Lean.CodeCompleteBy"/>
Refer to this link for details: Define a default value or copy a value to a field

On a work item I've got 2 combos; the 2nd combo's values are dependent on the 1st

On a work item I've got 2 combos where the 2nd combo's values are dependent on the 1st.
e.g. The 1st combo has 2 allowedvalues ("vowels", "consonants"), 2nd combo would show a,e,i,o,u if the first was set to vowels etc.
Any idea how I can do this?
someting like dis works
<FIELD name="Response" refname="Response" type="String" > <!-- values change depending on Category-->
<WHEN field="Category" value="1">
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="111" />
<LISTITEM value="1111" />
</ALLOWEDVALUES>
</WHEN>
<WHEN field="Category" value="2">
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="222" />
<LISTITEM value="2222" />
</ALLOWEDVALUES>
</WHEN>
</FIELD>
While you can do this it does not work with large lists as you can quickly hit the maximum limit for the size of a work item. It is not really a recommended practice.

TFS2012 Task work item definition - Update 'Remaining Work' with 'Original Estimate' whenever 'Remaining Work' is empty

On vs2013: tools > process editor > work item types > open WIT from server.
By editing the Task work item rules, I have come out with the following xml item definition:
<FieldDefinition name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure">
<WHENCHANGED field="Microsoft.VSTS.Scheduling.OriginalEstimate">
<COPY for="[global]\Project Collection Valid Users" from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
</WHENCHANGED>
</FieldDefinition>
What I am trying to achieve is sth more like this:
<FieldDefinition name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure">
<WHENCHANGED field="Microsoft.VSTS.Scheduling.OriginalEstimate">
<WHEN field="Microsoft.VSTS.Scheduling.RemainingWork" value="">
<COPY for="[global]\Project Collection Valid Users" from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
</WHEN>
</WHENCHANGED>
</FieldDefinition>
The problem is what I have now is not working for me (whenever I change Original Estimate, Remaining Work is not being updated), and I can't figure out how to stick in the WHEN clause.
I finally changed the Task tfs field definition for my project, via witadmin export/import:
On a Developer Command Prompt for VS2013
> witadmin exportwitd /collection:http://myTFSserver:8080/tfs/DefaultCollection /p:myTFSProject /n:Task /f:"c:\tfs\Task.xml"
replace the relevant section on Task.xml
<FIELD name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure" formula="sum">
<WHENCHANGED field="Microsoft.VSTS.Scheduling.OriginalEstimate">
<COPY for="[global]\Project Collection Valid Users" from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
</WHEN>
</FIELD>
with
<FIELD name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure" formula="sum">
<WHEN field="Microsoft.VSTS.Scheduling.RemainingWork" value="">
<COPY from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
</WHEN>
</FIELD>
then convey the change
> witadmin importwitd /collection:http://myTFSserver:8080/tfs/DefaultCollection /p:myTFSProject /f:"c:\tfs\Task.xml"
I can't think of a way to do what you want with just WITD.
Another (more complex) option is to create an ISubscriber plug-in that you deploy to your TFS. It can detect whenever your work items are changed and update fields appropriately using any logic you can write in C#.

How do I change field value case to be 'Camel' format?

I have custom field of string type in TFS work item with allowed values: "Yes", "No", And "Probably".
<FIELD reportable="dimension" type="String" name="Help Authoring"
refname="Custom.HelpAuthoring">
<HELPTEXT>Should 'Help Authoring' team to update own stuff</HELPTEXT>
<ALLOWEDVALUES>
<LISTITEM value="Yes" />
<LISTITEM value="No" />
<LISTITEM value="Probably" />
</ALLOWEDVALUES>
<DEFAULT from="value" value="No" />
</FIELD>
After importing work item into TFS project the 1st symbol case of "Probably" was changed to lower case. So now it is "probably". It looks ugly. while "Yes" and "No" are still in "Camel"-format.
Q1. Why allowed field value is changed?
Q2. How to prevent that?
P.S. To have values consistent I've tried to change "Yes" and "No" to "yes" and "no" but after importing they left in 'Camel'...
Unfortunately, once a constant like this is imported into work items for a Team Project Collection, it's there to stay. If you feel strongly about this, log a bug with Microsoft on the Visual Studio Connect site.
One possible(?) workaround is to create a global list with the values that you want, then use that for the ALLOWEDVALUES.
<?xml version="1.0" encoding="utf-8"?>
<gl:GLOBALLISTS xmlns:gl="http://schemas.microsoft.com/VisualStudio/2005/workitemtracking/globallists">
<GLOBALLIST name="Help Authoring Values">
<LISTITEM value="Yes" />
<LISTITEM value="No" />
<LISTITEM value="Probably" />
</GLOBALLIST>
</gl:GLOBALLISTS>
Use witadmin importgloballist /collection:http://yourserver:8080/tfs/collection /f:FileName to import it.
Then in the work item type, replace your <LISTITEM>'s with:
<ALLOWEDVALUES>
<GLOBALLIST name="Help Authoring Values" />
</ALLOWEDVALUES>

Resources