Perform logic on change of DateTime field

 Writing business logic on change of DateTime field in CRM portal using jQuery is different than normal on change function.

eg. If we want to check whether entered date is in past or not then we will use following syntax : 

In our case Start Date is the field where we are adding validation. Schema name for start date is new_startdate


var dpcontrol = $("#new_startdate_datepicker_description").closest("div.control");
        $(dpcontrol).on("dp.change", function (e)   
        { 
          var dateVal = $("#new_startdate").val();
                    if (dateVal != null) {
                        var newDate = new Date(dateVal), now = new Date();  
                        newDate.setHours(0,0,0,0); now.setHours(0,0,0,0);                	                 
                    if (newDate < now) {
                        alert("Date is in past. Please select valid date.");
			            $("#new_startdate_datepicker_description").val('');
                    }
                    }
        });

Comments

Popular posts from this blog

Accessing Fields on QuickView Form through javaScript

ADF - (Part 2) Integrate Data From CRM to External system

Power Apps Portals - Lock/Unlock User Account for Invalid Sign In Attempt