CRM 2011 – Javascript to set the current date and time

A quick blog entry and a suprisingly easy and small piece of code

In the code below I have function which gets triggered when a user ticks the confirm Closed checkbox it then sets the current date and time.

if the user untick the checkbox I wipe the date and time value.

The date functionality in javascript holds the current time as well

 function confirmClosedOnChange() {
 var closedConfirmed = Xrm.Page.getAttribute("new_closedconfirmed").getValue()

if (closedConfirmed) {
var currentDateTime = new Date();
Xrm.Page.getAttribute("new_confirmedcloseddate").setValue(currentDateTime);
} else {

Xrm.Page.getAttribute("new_confirmedcloseddate").setValue(null);
}
 }
 

4 thoughts on “CRM 2011 – Javascript to set the current date and time

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.