0

Setting Default Values on a Readonly work item field in TFS 2013

by Angela 4. March 2015 14:07

It’s actually a bit more complicated than that… What I was trying to do was set the Assigned To field on a NEW work item to a particular person, and then lock it in.  So new work items of a specific type can only ever be assigned to a particular person… The Assigned to dropdown would only ever get the full list of team members after it was transitioned away from the New state.

I tried a lot of things that felt like they SHOULD have worked. It appeared that I could do either set a field default, or make it read-only, but not both.  Here are the things I tried:

  1. I tried setting the field itself to both have a default value and be read-only at the field definition level, but it appears as a read-only blank field.
  2. I tried setting the field to have the default value, then added a WHEN clause to the field to set it to read-only when System.State = new. It appears as a read-only blank field.
  3. I tried setting the field to be read-only, then added a WHEN clause to set the field Default value during the transition into the new state (see below). It appears as a read-only blank field.
  4. I tried setting the field to have the default value, then set the field to read-only during the transition into the new state (see below). It appears as a read-only blank field.
  5. I tried setting the Assigned to field to be both set with a default value, and set to read-only in the New transition. Nothing was set at the field level. It appears as a read-only blank field.

Is read-only always processed before default value rules are set regardless of how you do it? I wasn’t sure, and I did run across the order of operations docs and it does not address read-only. :: SIGH::

If I remove the Read-only rule from every approach, the field defaults properly, making me think what I want to do is just not supported.  After scouring a lot of MSDN documentation, I have no reason to think otherwise but when I find out for sure I’ll let you know. Anyone see something else I am doing wrong? Or know for sure if it is supported or not? If so, please let me know! It’s kind of driving me crazy.  In the meantime, I did think of a workaround.   Instead of making the field read-only, I reduced the valid choices in the drop down while the item is in the new state to the one person it can be.  Not exactly read-only, but they can't change it to another value so it is effectively read-only...

<FieldDefinition name="Assigned To" refname="System.AssignedTo" type="String" syncnamechanges="true" reportable="dimension">
  <ALLOWEXISTINGVALUE />
  <ALLOWEDVALUES expanditems="true">
    <LISTITEM value="[project]\Analysts" />
  </ALLOWEDVALUES>
  <DEFAULT from="value" value="Joy" />
  <VALIDUSER />
  <WHEN field="System.State" value="New">
    <ALLOWEDVALUES expanditems="true">
      <LISTITEM value="Joy" />
    </ALLOWEDVALUES>
  </WHEN>
</FieldDefinition>

Powered by BlogEngine.NET 2.7.0.0
Original Design by Laptop Geek, Adapted by onesoft