sethours updating time part but not the date part in date time field RRS feed

  • Question

  • I've a datetime field with date only as format. Also, I've added a script at onload so that whenever a record is accessed 12:00 should be added to that field. It works as expected and add 12 hours to the time part. But it do not update the date accordingly.

    For example, I've Date Become Manager field and its value is 'Thu Apr 30 23:00:00 UTC-1200 1992'. And after adding 12 hours it updates the time part as 'Thu Apr 30 12:00:00 UTC-1200 1992' but do not add anything to its date. Following is my snippet for this to update.

    function updateFields(field)
    	var dateField = Xrm.Page.getAttribute(field);
    	if(dateField.getValue()== null)
    		dateField.setValue(new Date());
    	dateField.setValue(dateField.getValue().setHours(12, 0, 0));

    Please let me know if I am doing something wrong in it.

    Tuesday, September 22, 2015 7:56 AM

All replies

  • Hello,

    Try to replace line

    dateField.setValue(dateField.getValue().setHours(12, 0, 0));


    dateField.setValue(dateField.getValue().setHours(dateField.getValue().getHours() + 12));

    Dynamics CRM MVP
    My blog

    Tuesday, September 22, 2015 8:08 AM