Tuesday, January 20, 2015

Show only Time for Date Time Attribute

In CRM you can show only Date part of date time attribute, but not only time.

To show only date part of date time attribute, you need to go field customization and change Format as Date. 


You can show only time for date time attribute either by modifying CRM entity form HTML using Javascript or by adding web resource.

Modifying CRM form HTML (DOM) is not supported, so I will go with web resource.

1.       Add HTML web resource on your form.
2.       Set HTML web resource properties like, Number of rows, scrolling border, formatting etc.
3.       Add web resource on your form, This HTML web resource should be look like attribute on Form, so set properties accordingly.
4.       Add Jquery latest library in your entity form libraries.

5.       Add Following code into you HTML web resource. 


1.       Change < script type="text/javascript" src="new_jquery_1.10.2.js" > < /script >  as per your JQuery library name.
2.       Hide your date field on form.
3.       Save and publish customization.

Here is your output


4 comments:

  1. this allows to display the Time only but, how to save Time value in CRM?

    ReplyDelete
  2. Its given in above example

    var dateObj = new Date();
    dateObj = new Date(1900, 01, 01, hours, mins, 0, 0);
    //Set selected time to Date time attribute
    parent.Xrm.Page.getAttribute("new_date").setValue(dateObj);

    once time is changed, it will set value to date time attribute, and when record is saved new time will be saved .

    ReplyDelete
  3. Hi, This can't seem to work. Please assist

    ReplyDelete
  4. Hi Mahadeo,
    This works like charm. But the only drawback I am facing is the selected dropdown value gets back to 12AM on form refresh. It would make sense if it retains whatever value selected previously by the user even after refresh. Can you reproduce this behavior? Is this happening only for me? Please let me know. Thanks again.

    ReplyDelete