Hello,
We have 4 DateTime fields on the form which are used to fill different sale completion dates. Let's say fields are Sale1, Sale2, Sale3, Sale4. We do not want our associates to select "future date" as a sale date. Let's say if today's date is 08/29/2021, the associate should not be able to select anything in future. All the dates in the future should be disabled(greyed out). I know we can validate the date and throw notification that future date cant be selected. I like to find out if there is a way we can grey out all future dates for the field. This we should be doing for all the four fields. Any help on this will be appreciated
Thanks
Thanks
This is perfect. Thank you
from my previous code change this line
var dateFieldName = "new_date1";
to
var dateFieldName = executionContext.getEventSource().getName();
in this way the code can get the attribute name dynamically. Of course the function needs to be attached to the 4 field onchange events and the "Pass execution context as first parameter" checked
hope it helps
Hello Guido,
Thanks for responding. Yeah seems like there is no easier way to disable those fields. I have similar query to show alert when they select future date but not to restrict future dates completely
Hi,
Please refer to the following issue in the Community of Power Apps:
Solved: Disable the future dates in datepicker - Power Platform Community (microsoft.com)
It cannot be greyed out.
But an OnChange event with JavaScript on the date field could be a wise choice.
For example, the Birthday field in Contact form should not be a future date.
If a future date is selected for the Birthday field, there will be an alert and the field will be empty.
The code snippet is something like:
var startDate = Xrm.Page.getAttribute('birthdate').getValue();
var todayDate = new Date();
todayDate.setHours(0,0,0);
if (startDate > todayDate)
{
alert("DOB is greater than today's date");
Xrm.Page.getAttribute('birthdate').setValue(null);
}
it's not possible to gray out future date but you can attach a javascript function on the onchange event of the datetime field. For example:
function CheckDate(executionContext) { var formContext = executionContext.getFormContext(); var dateFieldName = "new_date1"; var fieldValue = formContext.getAttribute(dateFieldName).getValue(); if (fieldValue != null) { var fieldValueOnlyDate = fieldValue.setHours(0,0,0,0); var today = new Date(); today.setHours(0,0,0,0); if (fieldValueOnlyDate > today) { var alertMessage = { text: "Date can't be in the future" }; Xrm.Navigation.openAlertDialog(alertMessage); formContext.getAttribute(dateFieldName).setValue(today); } } }
note: code has not been tested and if you plan to run the same code on multiple fields it should be adapted
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Eugen Podkorytov
106
Muhammad Shahzad Sh...
106
Most Valuable Professional