Monday, October 25, 2021

How to restrict future date in MS CRM 365

Recently our client has came with the requirement that, they don’t want to allow a future date selection for a particular field on Microsoft Dynamics CRM form.

Well, it is not a complex task to implement. Here is the sample code for it-

function restrictFutureDate() {

    if (Xrm.Page.getControl("Date_Field")) {
        var getfieldValue = Xrm.Page.getAttribute("Date_Field").getValue();
   
        var today = new Date();
   
        if (getfieldValue > today) {
   
            Xrm.Page.getControl("Date_Field").setNotification("Future date is not allowed!", "DATEERROR");
        } else {
   
            Xrm.Page.getControl("Date_Field").clearNotification("DATEERROR");
        }

    }
}

No comments:

Post a Comment

QueryExpression vs. FetchXML in MS CRM with C#

Microsoft Dynamics CRM (Customer Relationship Management) is a powerful platform that helps organizations streamline their business processe...