<?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>MSCRM Blogger &#187; tasks</title>
	<atom:link href="http://mscrmblogger.com/tag/tasks/feed/" rel="self" type="application/rss+xml" />
	<link>http://mscrmblogger.com</link>
	<description>Achieving it all with Microsoft Dynamics CRM™</description>
	<lastBuildDate>Fri, 09 Jul 2010 14:57:43 +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>Auto-Update Duration/End Time JScript</title>
		<link>http://mscrmblogger.com/2009/09/28/auto-update-durationend-time-jscript/</link>
		<comments>http://mscrmblogger.com/2009/09/28/auto-update-durationend-time-jscript/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 15:21:30 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>
		<category><![CDATA[onload event]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tasks]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=113</guid>
		<description><![CDATA[Sometimes you need to be able to have preset values, and have the duration auto-update.  In this example, I will make the actual durations auto-update when one of the fields is changed.  If the duration is changed, then the end date will be changed.]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to be able to have preset values, and have the duration auto-update.  In this example, I will make the actual durations auto-update when one of the fields is changed.  If the duration is changed, then the end date will be changed.  Special thanks to Stephan Bayer for thinking of the idea.  We worked together to bring you this implementation of the <i>Auto-Update Duration/End Time JScript</i>.</p>
<p><b>Check out the video of how it works</b></p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/6Ccsn58SnFE&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6Ccsn58SnFE&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Granted, in my implementation I added a field for time deductions, but I have commented it out in the code.  If you add a duration, just change the script to use that field.  Also, please make sure to add the fields to the required parameters for the event.  I would hate for someone&#8217;s code to stop working because a field was removed from the form.</p>
<p><b>This code is for the Start, End, and Deduct (if you have it) on change events:</b></p>
<pre name="code" class="javascript">
// Get End and Start
var start = crmForm.all.actualstart.DataValue;
var end = crmForm.all.actualend.DataValue;
// Can't calculate without any data
if (start==undefined || start==null || end==undefined || end==null) {
	return;
}

// Get 1 day in milliseconds
var one_minute=1000*60;

// Get time in days...
var time = (end-start)/one_minute;

/*
// Get the deduction
var deduct = crmForm.all.it_timeentry_deduct.DataValue
if (deduct!=undefined &#038;&#038; deduct!=null)
{
  time = time - deduct;
}
*/

// Can't be less than 0.
if (time&lt;0) time=0;

// Set the duration
crmForm.all.actualdurationminutes.DataValue = time;
</pre>
<p><b>This code is for the onchange event of the Duration field:</b></p>
<pre name="code" class="javascript">
var start = crmForm.all.actualstart.DataValue;
var duration = crmForm.all.actualdurationminutes.DataValue;
// Can't calculate without any data
if (start==undefined || start==null || duration==undefined || duration==null)
{
	return;
}

var end = start;
end.setMinutes(end.getMinutes()+duration);

/*
var deduct = crmForm.all.it_timeentry_deduct.DataValue
if (deduct!=undefined &#038;&#038; deduct!=null)
{
  end.setMinutes(end.getMinutes()+deduct);
}
*/

crmForm.all.actualend.DataValue=end;
</pre>
<p>To preset the duration, start time and end time, I added the following script to the form&#8217;s onload event</p>
<pre name="code" class="javascript">
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;

if (crmForm.FormType==CRM_FORM_TYPE_CREATE)
{
	var duration = 10;
	var start = new Date();
	crmForm.all.actualstart.DataValue = start;
	crmForm.all.actualdurationminutes.DataValue = duration;
	var start = crmForm.all.actualstart.DataValue;

	var end = start;
	end.setMinutes(end.getMinutes()+duration);

	crmForm.all.actualend.DataValue=end;
}
</pre>
<p>If you have any questions about this implementation or would like assistance implementing it somewhere, please post a comment and let us know.</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/09/28/auto-update-durationend-time-jscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
