简体   繁体   中英

Hide the date part on a DateTime field MS Dynamics CRM 2011

I would like to have a time-only field on my CRM form (MS Dynamics CRM 2011). As it is apparently not possible, I plan to use a DateTime field and hide the date part.

How can I hide the date part on a DateTime field using JavaScript ?

A supported method would be to instead create a new attribute on the entity (a text field called Time) and put that on the form. Take your current DateTime field on the form, make it invisible, then use a Javascript event on the on the onChange event of the form to validate that it is a valid time.

Then in the onSave event of the form, copy the time over to the Date Time attribute that is hidden on the form (also remember to mark it as Force Submit Always ).

That way the user won't be forced to pick a day (although the time selection will be arguably more difficult)

// Set the date 
document.getElementById("field_name").DataValue = new Date(2000, 1, 1);
// Hide the date part
document.getElementById("field_name").childNodes[0].childNodes[0].style.display =
    "none";
document.getElementById("field_name").childNodes[0].childNodes[1].style.display =
    "none";
var DateTimeA = new Date();
var temp = DateTimeA.Split("/");
DateTimeA = temp[0];

Example of using a part of a date...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM