0
votes

In TFS 2012 I have edited the Task Work Item so that it automatically copies the original estimate over to the remaining estimate field when the original estimate is changed.

My Code:

<FieldDefinition name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure">
  <WHENCHANGED field="Microsoft.VSTS.Scheduling.OriginalEstimate">
    <COPY from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
  </WHENCHANGED>
  <HELPTEXT>An estimate of the number of units of work remaining to complete this task</HELPTEXT>
</FieldDefinition>

However when you enter a value in the original estimate field for a task and hit save, it copies across the previous value and not the current.

How do I fix it so that it copies the new value across upon saving the task and not the previous saved value?

Edit: This is the xml pulled from the entire file view rather than TFS power tools view of just that item. It for some reason showed <fieldDefinition> instead of <field>:

<FIELD name="Remaining Work" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="Double" reportable="measure">
    <WHENCHANGED field="Microsoft.VSTS.Scheduling.OriginalEstimate">
        <COPY from="field" field="Microsoft.VSTS.Scheduling.OriginalEstimate" />
    </WHENCHANGED>
    <HELPTEXT>An estimate of the number of units of work remaining to complete this task</HELPTEXT>
</FIELD>
2
Is there a reason you're using <FieldDefinition /> instead of <FIELD /> to define the field? And are there any other rules that might be updating either the RemainingWork or OriginalEstimate fields?Richard Banks
I pulled the xml from TFS power tools view xml for the item but when I look at the whole file it is <Field> and not <FieldDefintion>. I don't know why. There's no other field that changes it according to a search of the full xml.Chrises
OK. Can you have a look at the detailed history of the work item and see if there are any entries showing the field value changing?Richard Banks
It's passing in the previous value not the current new value according to the history e.g. Original Estimate Old 1 New 2 Remaining Work Old 0 New 1Chrises

2 Answers

1
votes

We've accomplished this task using a transition from when the work item moves from New to In Progress

<Transition from="New" to="In Progress">
  <REASONS>
    <DEFAULTREASON value="In Progress">
      <FIELDS>
        <FIELD refname="System.AssignedTo">
          <COPY from="currentuser" />
        </FIELD>
        <FIELD refname="Microsoft.VSTS.Scheduling.OriginalEstimate">
          <WHEN field="Microsoft.VSTS.Scheduling.OriginalEstimate" value="">
            <COPY from="field" field="Microsoft.VSTS.Scheduling.RemainingWork" />
          </WHEN>
        </FIELD>
      </FIELDS>
    </DEFAULTREASON>
  </REASONS>
</Transition>

If the Original Estimate field does not have a value set, it will use the value stored in Remaining Work.

0
votes

Basically, you can't do what you're trying to do in the way you are trying to do it. In order for that to work, you'd need to effectively save the work item twice. The value that is stored in TFS when the WHENCHANGED is triggered is still the old value. The new value doesn't get saved (and thus can't actually be accessed) until after the save operation completes. This is actually the expected behavior.

The suggested alternative of putting the sync of the two fields into a state transition would work. You can also use the TFS API to achieve this kind of functionality after the save operation completes.