locked
How to create a Business Rule to prevent entry of Dates prior to Today? Seems this simple validation isn't possible? RRS feed

  • Question

  • Customer has a very simple business rule requirement. We don't want users to enter dates prior to today for many date fields. This is a very simple date entry requirement. I look to Business Rules for this, since this is the sort of thing you expect to it handle very easily.

    But all I seem to be able to do is specify a hard coded date (rather pointless) or a formula based on some other date field. Nowhere can I find a reference to Today.

    So we have to start writing JavaScript or a real time workflow for this rather simple requirement? What's the point of business rules then?

    Friday, December 19, 2014 3:38 PM

All replies

  • function CheckDate() {
        var dateReceived = Xrm.Page.getAttribute("ENTERFIELDSCHEMANAME").getValue();
        var currentDate = new Date();
    
        if (dateReceived - currentDate < 0) {
            ClearField("ENTERFIELDSCHEMANAME");
            //Xrm.Page.getControl("rpa_datereceived").setFocus();
    
            var message = "Date Received can not be set to a past date. Select an future date.";
            Xrm.Page.ui.setFormNotification(message, "ERROR", "futureDateMessage");// JavaScript source code
    
        }
    }
            function ClearField(fieldName) {
                var field = Xrm.Page.data.entity.attributes.get(fieldName);
    
                if ((field != null) && (field.getValue() != null))
                    field.setValue(null);
            }
    I hope you like ready food.

    Regards Faisal

    Friday, December 19, 2014 4:32 PM
  • Thanks for the response, but you misread the Question. The whole idea of Business Rules is to avoid writing JavaScript, since that needs a developer. Looks like MS don't handle this very simple requirement.
    Tuesday, December 23, 2014 9:24 AM