Saturday, September 8, 2012

CRM 2011 - javascript to compare with today datetime

function VerifyIssueDate()
{

var today=new Date();
var issueDate=Xrm.Page.data.entity.attributes.get("jmh_issuedate");

if(issueDate != null && issueDate.getValue() != null )
{
issueDateValue=issueDate.getValue();
if(issueDateValue.getFullYear() >  today.getFullYear())
{
alert("Issue Date must be on or before today");
issueDate.setValue(null);
}
else if (issueDateValue.getMonth() > today.getMonth() )
{
alert("Issue Date must be on or before today");
issueDate.setValue(null);
}
else if (issueDateValue.getDate() >  today.getDate() )
{
alert("Issue Date must be on or before today");
issueDate.setValue(null);
}
}
}


function VerifyExpiryDate()
{
var today=new Date();
var expiryDate=Xrm.Page.data.entity.attributes.get("jmh_expirydate");

if(expiryDate != null && expiryDate.getValue() != null)
{
var expiryDateValue= expiryDate.getValue();


if(expiryDateValue.getFullYear() <  today.getFullYear())
{
alert("Expiry Date must be on or after today");
expiryDate.setValue(null);
}
else if (expiryDateValue.getMonth() < today.getMonth() )
{
alert("Expiry Date must be on or after today");
expiryDate.setValue(null);
}
else if (expiryDateValue.getDate() <  today.getDate() )
{
alert("Expiry Date must be on or after today");
expiryDate.setValue(null);
}


}
}

1 comment: