In my WITD, I have some xml like this in my FIELD tag:
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="Yes" />
<LISTITEM value="No" />
</ALLOWEDVALUES>
<DEFAULT from="value" value="No" />
I can get the allowed values from the API by getting an instance of class FieldDefinition and referencing the AllowedValues property.
How can I get the DEFAULT tag's value from the Api?
You could create a new work item with a work item type that has your field and then check the value of the field on the new work item. You don't need to save the work item to check the field value. It should contain the default value you are after.
There's no API for retrieving default values. Another approach is to parse the value from the WITD XML using WorkItemType.Export Method
var xml = wit.Export(false);
Related
I would like to add a custom rule to set a default History when changing the status.
<FIELD name="History" refname="System.History" type="History">
<HELPTEXT>Discussion thread plus automatic record of changes</HELPTEXT>
<WHENCHANGED field="System.State">
<DEFAULT from="value" value="State changed" />
</WHENCHANGED>
</FIELD>
getting below error.
**Error importing work item type definition:
TF26062: Rule '<DEFAULT from="value" value="State changed" />' is not supported for the field 'System.History'.**
any help would be appreciated.
Checking the Process xml file, you would like to add a value for the Discussion field when the status of this work item changes.
Discussion field of the work item is not supported to use custom rule to set a value when changing status.
You could consider create a new custom field to apply your rule.
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:
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".
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/
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