Validate TFS 2017 Boolean field - tfs

I am trying to edit work item templates to make use of the new Boolean field in TFS 2017, and want a particular field to be set to true before a status can be changed. Is there any way to do this? It would appear ALLOWEDVALUES and MATCH aren't supported, which could have potentially helped

You can do that by applying a conditional rule based on your requirement just as Hamid mentioned above.
Boolean is just a data type, we can add a custom Boolean field and add a checkbox for it.
Use the following syntax to add a Boolean field within the FIELDS
section of the WIT definition.
<FIELD name="Triagelc" refname="lc.Triage" type="Boolean" >
<DEFAULT from="value" value="True" />
<HELPTEXT>Triage work item</HELPTEXT>
</FIELD>
And then add the following syntax within the FORM section to have
the field appear on the form.
<Control Label="Triagelc" Type="FieldControl" FieldName="lc.Triage" />
The field will appear as a checkbox on the form.
Then apply a When rule for target filed, thus when the specified
Boolean field has the specified value, the When rule is applied to
the target field.
eg1:
Apply a "When" rule for Description field in Task work item type :
<FieldDefinition name="Description" refname="System.Description" type="HTML">
<WHEN field="lc.Triage" value="True">
<REQUIRED />
</WHEN>
</FieldDefinition>
Then when set the value to True, the Description area is required, it cannot be empty.
eg2:
You can also use READONLY rule to restrict other areas:
<FieldDefinition name="Assigned To" refname="System.AssignedTo" type="String" syncnamechanges="true" reportable="dimension">
<WHEN field="lc.Triage" value="True">
<READONLY />
</WHEN>
<ALLOWEXISTINGVALUE />
<HELPTEXT>The person currently owning this task</HELPTEXT>
</FieldDefinition>
Thus, when the Boolean field value is True, Assigned To field is read only, otherwise you can assign to the existing users.
UPDATE:
eg3:
We can not achieve that directly with the boolean data type. As a workaround you can try below ways:
Apply the When rule and embed the Copy rule (Copy True as the
value) for the "Triagelc" boolean field in this example. Thus when
the status is Done, Triagelc can set the value to "True"
automatically, then save. But in this way the value still can be
modified to false. Reference below screenshot 1:
<FieldDefinition name="Triagelc" refname="lc.Triage" type="Boolean">
<WHEN field="System.State" value="Done">
<COPY from="value" value="True" />
</WHEN>
<HELPTEXT>Triage work item</HELPTEXT>
</FieldDefinition>
Set the default value to True for Boolean field (Triagelc
field in this example), then apply When rule with READONLY rule
embedded. This way should be meet your requirement (Once done the value cannot be changed anymore). Reference below screenshot 2:
<FieldDefinition name="Triagelc" refname="lc.Triage" type="Boolean">
<DEFAULT from="value" value="True" />
<WHEN field="System.State" value="Done">
<READONLY />
</WHEN>
<HELPTEXT>Triage work item</HELPTEXT>
</FieldDefinition>
Please note that:
The Boolean data type field is only supported for VSTS and TFS 2017.2
and later versions.
Screenshot 1:
Screenshot 2:

Related

TFS. How to set <required changes> field if value has been already set?

I have some custom field in Bug WI. I want to set it to but even if there was not NULL value after state of WI changed.
Example: Let's say I have that config in transition:
<TRANSITION from="Active" to="Resolved">
<FIELD name="Version">
<REQUIRED />
</FIELD>
</TRANSITION>
When bug change it's state from Active to Resolved first time it works (field become yellow - fill required to proceed), but after, if I change state to New, then to Active and then to Resolved, there is no request to CHANGE previous field value. I think it's need check with previous value, and if it's equal, then require from user another value. Any suggestions how to do that?
Thanks
Found a solution.
Created hidden field "TempVersion". In transition Resolved to New/Active I copy value of Version to TempVersion.
<FIELD refname="TempVersion">
<COPY from="field" field="Version" />
</FIELD>
In transition Active->Resolved added :
<TRANSITION from="Active" to="Resolved">
<FIELD name="Version">
<NOTSAMEAS field="TempVersion" />
<REQUIRED />
</FIELD>
</TRANSITION>
Seems like it works!
REQUIRED rule requires a user to specify a value for the field. Users cannot save a work item until they have assigned values to all required fields. In your scenario, as the field "Version" has been specified a value, there is no restriction.
Default work item rules can't compare values, you'll need to customize a work item control to achieve what you want. You can get start by following https://witcustomcontrols.codeplex.com/

Specifying suggested values for a TFS Boolean Field

We're using a heavily customised set of TFS WorkItem Types for our development process.
One such type has a boolean field on it, however when we go to set this field you have to type in either "True" or "False", this is frustrating and I'd much rather have a checkbox or a set of suggested values we can pick from. Here's the field xml:
<FieldDefinition name="My Field" refname="My.BooleanField" type="Boolean">
<SUGGESTEDVALUES expanditems="true">
<LISTITEM value="True" />
<LISTITEM value="False" />
</SUGGESTEDVALUES>
</FieldDefinition>
However this doesn't work.
I was hoping I could change the control from a FieldControl to something more user friendly (like you can with DateTimes) but again I've had no success.
Is there a way I can create a boolean field on a TFS WorkItemType which doesn't require the user to type "True" or "False" or do I have to set it as a string to use Suggested Values?
You could change <SUGGESTEDVALUES> to <ALLOWEDVALUES>. That tells the FieldControl to render a dropdown box:
<ALLOWEDVALUES>
<LISTITEM value="true" />
<LISTITEM value="false" />
</ALLOWEDVALUES>
That should make your life easier. Type Boolean is not an available field type, so you'll have to use string as the underlying data type. Check the field definition:
type="String | Integer | Double | DateTime | PlainText | HTML | History | TreePath | GUID"
So you'll end up with:
<FieldDefinition name="My Field" refname="My.BooleanField" type="String">
<ALLOWEDVALUES>
<LISTITEM value="true" />
<LISTITEM value="false" />
</ALLOWEDVALUES>
</FieldDefinition>
A checkbox control is currently only available by deploying a custom control to the machine of all your users. There's a lot of demand for this feature, I'd expect Microsoft to support it in the future in in the form of the new Process Customization features that are available on Visual Studio Team Services.
It only took 5 years and 3 major TFS versions, but the Checkbox control is finally part of the available Field Types!
With TFS 2015.2 you'll be able to chose the boolean type for a field.
The documentation does not include the change as of July '16 but this blog post confirms it.
Be aware that some important rules are not supported by this field type, such as "MATCH", "ALLOWEDVALUES" and "PROHIBITEDVALUES".

Setting TFS field as readonly based on area path

I have custom TFS form with a text field comment. I want this field to be readonly for most of the area paths except 4. How can I add condition to set the field as read only?
basically, when the area id is 1,2,3,4 the comment field should not be readonly else it should be readonly.
I tried the following, but it didn't work
<FIELD name="Comment" refname="test.test.comment" type="Integer">
<WHENNOT field="System.AreaId" value="1">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="2">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="3">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="4">
<READONLY />
</WHENNOT>
</FIELD>
I dont want to write when conditions because these 4 are constant and I have about 40 other area ids which keeps increasing.
No, "And" multiple "WHENNOT" conditions doesn't work. See: Work Item state change rules in TFS - Any way to use "AND"s or "OR"s?
So, instead of using work item rules, you need to work with custom work item control. Determine when to set Comment filed to be readonly via using TFS API. Check this link for the details on how to work with custom work item control: https://witcustomcontrols.codeplex.com/

TFS 2010 Multiple condition for a work item field in TFS

I am using TFS 2010.
My requirement is to set allowed values for a field based on two conditions.
I have tried using nested WHEN, but i got error and i found in the forums that it is not possible.
How can I achieve this?
Field ‘Step’ value of “Code Review” and the field ‘Test Group’ value was “UAT only”, then the selection in the field ‘Step’ drop down would be “Code Review”, “Unit Test”, or “UAT”
Field ‘Step’ value of “Requirement”, then have the selections in the drop down box “Requirement”, or “Design”
For Example
<FieldDefinition name="Assigned To" >
<WHEN field="System.AreaId" value="9">
<ALLOWEDVALUES expanditems="true" filteritems="excludegroups">
<LISTITEM value="1" />
</ALLOWEDVALUES>
</WHEN>
<WHEN field="System.StateId" value="103">
<ALLOWEDVALUES expanditems="true" filteritems="excludegroups">
<LISTITEM value="2" />
</ALLOWEDVALUES>
</WHEN>
</FieldDefinition>
In the above XML, System will check OR condition either Area ID = 9 or StateID = 103. But my requirement is to check AND condition, if both the condition satisifies, then i have to set few allowedvalues.
The way I typically handle this is just to combine the 2 fields into one, and give all possible combinations as allowed values.
So for example you might have a drop-down with the following choices:
UAT Only - Code Review
UAT Only - Unit Test
UAT Only - UAT
Requirement - Requirement
Requirement - Design

How can I prohibit State change from Proposed to Active in TFS Requirement work-item based on value of another field?

I've added department approvals to the standard CMMI-Template Requirement work-item. I'd like to limit the System.State field such that it can only be changed from Proposed to Active when all department approvals are set to "Yes".
I've tried the following change to Requirement.xml
<FIELD name="State" refname="System.State" type="String" reportable="dimension">
<WHEN field="Approval.Marketing" value="No">
<READONLY />
</WHEN>
<WHEN field="Approval.Quality" value="No">
<READONLY />
</WHEN>
<WHEN field="Approval.RD" value="No">
<READONLY />
</WHEN>
<WHEN field="Approval.System" value="No">
<READONLY />
</WHEN>
<WHEN field="Approval.ProgManagement" value="No">
<READONLY />
</WHEN>
</FIELD>
This causes the State field to become READONLY if any of the approval fields are set to "No" which is what I want. However it causes problems when creating a new requirement since the approvals are all "No" initially and thus the initial "Proposed" default for State doesn't get set due to READONLY condition. What I'd like is to do is add logic to the WHEN conditions above to AND them with the condition System.State="Proposed". I tried nesting WHEN clauses such as
<FIELD name="State" refname="System.State" type="String" reportable="dimension">
<WHEN field="System.State" value="Proposed">
<WHEN field="Approval.Marketing" value="No">
<READONLY />
</WHEN>
. . .
</WHEN>
</FIELD>
But this gets an error on import that WHEN clause cannot contain WHEN. How can I prohibit State change from Proposed to Active when any of the Approval fields are set to "No"
I spent some time figuring out if I could come up with a variation that would work since you cannot set a default value for System.State in the way you can other fields. I probably went through 50 or so variations before I came up with something that works. Granted, it is not ideal but it would solve your problem after the initial creation.
You could, inside each of the transition states, add your when clauses. For my example I was using the priority field and doing something like:
<State value="Proposed">
<FIELDS>
<FIELD refname="Microsoft.VSTS.Common.ResolvedDate">
<EMPTY />
</FIELD>
...
<FIELD refname="System.State">
<WHEN field="Microsoft.VSTS.Common.Priority" value="2">
<READONLY />
</WHEN>
</FIELD>
</FIELDS>
</State>
You would have to add your clauses of course to the other states: active, closed and Resolved.
Once you do that, create a new Requirement. When you create a new requirement you have two options:
You can either set all the options to yes, set state to proposed and save. Then go back and set them to no and save.
Or
Change your custom fields all to default to yes.
Create Requirement and save. Edit it, switch all the values to no, Save.
Either way you choose to go, once this initial hurdle is over with the requirement creation. It will act how you wanted it to. In other words, if any of the values are no then it will make state readonly.
That was the best I could come up with given the restriction for the System.State field.

Resources