<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>stuartpreston.net &#187; Hack</title>
	<atom:link href="http://stuartpreston.net/blog/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuartpreston.net/blog</link>
	<description>Blog of Stuart Preston</description>
	<lastBuildDate>Fri, 06 Apr 2012 22:46:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>TFS WIT hacks: Setting a DateTime field based on String value in another field</title>
		<link>http://stuartpreston.net/blog/2009/11/09/tfs-wit-hacks-setting-a-datetime-field-based-on-string-value-in-another-field/</link>
		<comments>http://stuartpreston.net/blog/2009/11/09/tfs-wit-hacks-setting-a-datetime-field-based-on-string-value-in-another-field/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 23:48:13 +0000</pubDate>
		<dc:creator>Stuart Preston</dc:creator>
				<category><![CDATA[Team Foundation Server]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[WIT]]></category>

		<guid isPermaLink="false">http://stuartpreston.net/blog/?p=24</guid>
		<description><![CDATA[I recently responded to a question on a Microsoft discussion list.  The question was (paraphrased):
I need to get the clock value assigned to “Field B” when the value of “Field A” is changed to a specific value.  Field A allows Yes, No values only.
I need the exact time “Field A” gets assigned Yes. When it [...]]]></description>
			<content:encoded><![CDATA[<p>I recently responded to a question on a Microsoft discussion list.  The question was (paraphrased):</p>
<blockquote><p><em>I need to get the clock value assigned to “Field B” when the value of “Field A” is changed to a specific value.  Field A allows Yes, No values only.</em></p>
<p><em>I need the exact time “Field A” gets assigned Yes. When it goes back to No, I must not do anything with the value stored in “Field B”. Then if “Field A” gets assigned Yes one more time, I need “Field B” updated with the DateTime of when this assignment happened and not losing the value until next time field A gets triggered to Yes.</em></p></blockquote>
<p>Well I remembered doing something similar during some prototyping on <a href="http://scrumforteamsystem.com">Scrum for Team System</a>.  The initial trap is that when you set up a &lt;COPY from=”clock” /&gt; rule on a TFS WIT field, then Team Explorer refreshed this time after the work item is saved.  This is not the behaviour we wanted to see.  After a bit of experimentation, success!</p>
<pre class="csharpcode">      <span class="kwrd">&lt;</span><span class="html">FIELD</span> <span class="attr">name</span><span class="kwrd">="FieldA"</span> <span class="attr">refname</span><span class="kwrd">="Playground.FieldA"</span> <span class="attr">type</span><span class="kwrd">="String"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">COPY</span> <span class="attr">from</span><span class="kwrd">="value"</span> <span class="attr">value</span><span class="kwrd">="No"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ALLOWEDVALUES</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">LISTITEM</span> <span class="attr">value</span><span class="kwrd">="Yes"</span> <span class="kwrd">/&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">LISTITEM</span> <span class="attr">value</span><span class="kwrd">="No"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ALLOWEDVALUES</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">FIELD</span><span class="kwrd">&gt;</span>

      <span class="kwrd">&lt;</span><span class="html">FIELD</span> <span class="attr">name</span><span class="kwrd">="FieldB"</span> <span class="attr">refname</span><span class="kwrd">="Playground.FieldB"</span> <span class="attr">type</span><span class="kwrd">="DateTime"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">WHEN</span> <span class="attr">field</span><span class="kwrd">="Playground.FieldA"</span> <span class="attr">value</span><span class="kwrd">="Yes"</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">COPY</span> <span class="attr">from</span><span class="kwrd">="clock"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">WHEN</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">WHEN</span> <span class="attr">field</span><span class="kwrd">="Playground.FieldA"</span> <span class="attr">value</span><span class="kwrd">="No"</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">READONLY</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">WHEN</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">FIELD</span><span class="kwrd">&gt;</span></pre>
<p>As you can see, the trick is to deliberately set FieldB to &lt;READONLY /&gt; when FieldA is “No”.  I thought I’d post this here in case anyone else needs to do something similar.  A view of the history on the Work Item I edited confirms the modification works as required:</p>
<p><a href="http://stuartpreston.net/blog/wp-content/uploads/2009/11/clip_image0026.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[6]" src="http://stuartpreston.net/blog/wp-content/uploads/2009/11/clip_image0026_thumb.jpg" border="0" alt="clip_image002[6]" width="451" height="525" /></a></p>
<p>This sample should work on TFS2005, 2008 and all versions of 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://stuartpreston.net/blog/2009/11/09/tfs-wit-hacks-setting-a-datetime-field-based-on-string-value-in-another-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

