I want to view and select current and the future date
I want to view and select current and the future date
a couple of corrections to Leah Ju code:
1) this line
var date1 = new Date(date);
is not required, when you do a getValue against a datetime field, or is null (checked by the next line in that code) or it has a javascript Date object
2) this line
Xrm.Page.getAttribute("new_date").setValue(null);
should use formContext, so formContext.getAttribute("new_date").setValue(null);
3) this line
alert("Sorry,You can't select past day.");
alert works but you should use
Xrm.Navigation.openAlertDialog({text: "Sorry,You can't select past day."});
Hi unbeatable,
Unfortunately, you can’t restrict use select or view past date in the Date picker of the date field directly, there is no way to achieve it.
However, you can use javascript to date field OnChange event to prevent use filling past date in the field.
Just like following code:
function pastDate(executionContext) { var formContext = executionContext.getFormContext(); var today = new Date(); var date = formContext.getAttribute('new_date').getValue(); var date1 = new Date(date); if (date != null) { if (today > date1) { Xrm.Page.getAttribute("new_date").setValue(null); alert("Sorry,You can't select past day."); } } }
Test Result:
When I fill yesterday date, it will alert you.
when you click ok button of the dialog, the date field will be cleared.
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
André Arnaud de Cal... 291,602 Super User 2024 Season 2
Martin Dráb 230,340 Most Valuable Professional
nmaenpaa 101,156