Pat Delaney
Pat Delaney

Reputation: 117

TFS 2018 capture date when field value changed

I'm adding a field in a workitem and I want to capture in a separate field the date and time that the filed was changed. I have it working, sort of. When the user changes the dropdown list value to Yes, a field opens below that will be used to record the time the value about changed to Yes. When the user saves the worktime, the system adds the time of the save to that field. I can go back to that work item and I can see the value. But if I update any other information and save the workitem the time stamp is updated again to when the WIT was just saved. My desired workflow is to set the time only when that field is set. I also have a rule that will EMPTY the field if the Value was changed from Yes to No.

Here is the section of the field definitions for the fields in question.

      <FIELD name="Blocked" refname="Microsoft.VSTS.CMMI.Blocked" type="String" reportable="dimension" >
        <ALLOWEDVALUES expanditems="true">
          <LISTITEM value="Yes" />
          <LISTITEM value="No" />
        </ALLOWEDVALUES>
        <DEFAULT from="value" value="No"/>
      </FIELD>  
      <FIELD name="Date Blocked" refname="XXX.DateBlocked" type="DateTime" reportable="detail" >
        <WHEN field="Microsoft.VSTS.CMMI.Blocked" value="Yes">
          <SERVERDEFAULT from="clock" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CMMI.Blocked" value="No">
          <READONLY/>
          <EMPTY/>
        </WHEN>
        <HELPTEXT>The is the toole tip</HELPTEXT>
      </FIELD>

Upvotes: 0

Views: 84

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

But if I update any other information and save the workitem the time stamp is updated again to when the WIT was just saved

This is because when you update other information and save the workitem. The condition in below rule is still true. So that the Date Blocked field will be updated again.

<WHEN field="Microsoft.VSTS.CMMI.Blocked" value="Yes">
          <SERVERDEFAULT from="clock" />
</WHEN>

You can fix this issue by adding another condition WHENNOTCHANGED. See below:

<FIELD name="Date Blocked" refname="XXX.DateBlocked" type="DateTime" reportable="detail" >
        <WHENNOTCHANGED field="Microsoft.VSTS.CMMI.Blocked">  
           <READONLY />  
       </WHENNOTCHANGED> 
        <WHEN field="Microsoft.VSTS.CMMI.Blocked" value="Yes">
          <SERVERDEFAULT from="clock" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CMMI.Blocked" value="No">
          <READONLY/>
          <EMPTY/>
        </WHEN>
        <HELPTEXT>The is the toole tip</HELPTEXT>
      </FIELD>

By adding <WHENNOTCHANGED field="Microsoft.VSTS.CMMI.Blocked">, the Date Blocked will be made readonly and canot be changed if Blocked is not updated while other information is updated

Upvotes: 1

Related Questions