Sunday, July 19, 2009

CRM 4.0 Hide the date part of a DateTime field

So this is pretty easy but rare to face scenario. If you check DateTime field's format options, it says Date Only and Date And Time. But what if I want to have Time Only? This is what some one asked recently, and I thought, let me give this one a try. Again, unsupported and all that blah blah blah goes here, just get over with it and get to the good part.

function HidDatePart(targetFieldName)
crmForm.all[targetFieldName]DataValue = new Date();
document.getElementById(targetFieldName).childNodes[0].childNodes[0].style.display = "none";
document.getElementById(targetFieldName).childNodes[0].childNodes[1].style.display = "none";

just pass the targetFieldName parameter and you are good to go.

Remember you can't remove the date field using DOM operation, as it will start giving you errors.. Also by default time field is disabled, to enable it, it is necessary to add some value in Date Field.

Let me know if you need more help with this.

No comments: