11 February 2009

Prompt Backdated Disallowed on CRM datetime field

CRM 4 date time control manage to minimize the error on user input by allow them to select a date from drop down calendar. Now, real word business scenario might required more advance of date time validation on date time field input.

Given scenario: Follow Up Date must be greater or equal to today.
The most easiest way to achieve the requirement is by Javascript; let see how it works
every time user change the field, onchange event on CRM fire the javascript to verify the input.

 <br />
function FollowUpDate() <br />
{ <br />
var current=new Date(crmForm.all.createdon.DataValue); <br />
var days=-1; //To handle crmForm onCreate or onChange <br />
if(crmForm.all.createdon.DataValue==null) <br />
{ <br />
d=new Date(); <br />
current.setFullYear(d.getYear(),d.getMonth(),d.getDate()); <br />
days=0; <br />
} <br />
<br />
var selected=new Date (crmForm.all.followupby.DataValue); <br />
<br />
var ONE_DAY=1000*60*60*24; <br />
var different=selected-current; <br />
var indicator=Math.round(different/ONE_DAY);  <br />
<br />
alert("Backdated disallowed for 'Follow Up By'."); 

Hope this simple javascript can help :)


Post a Comment