Notifications
Announcements
No record found.
I must be missing this very basic requirement to validate the date a user enters isn't before TODAY. I can't see where this is possible with Business Rules. Am I missing something?
*This post is locked for comments
Hi Debra
You will need to use the following JS to perform this validation;
Function Form_onsave(executionObj)
{
var shouldSave = true;
if (shouldSave)
var contactDate = Xrm.Page.getAttribute('new_nextcontactdate').getValue();
if (contactDate != null) {
contactDate.setHours(0, 0, 0, 0);
// rest of the code
var today = new Date();
today.setHours(0, 0, 0, 0);
if (contactDate < today) {
alert("Date can not be less than today");
executionObj.getEventArgs().preventDefault();
}
I hope that helps :)
Best Wishes, Raz
The Business Rules feature doesn't provide a method for configuring every possible business rule you might have (unfortunately).
The two options I would evaluate are:
Best OOTB way is to create a Real Time Workflow-
Check condition - If "date field" is less than or equal to [process] 'execution time.
Then Stop workflow with status = cancelled [set properties for eg: "Date should be in Future only"]
I like this xrmbase; thank you. I'm always looking to push the envelope with OOTB. I didn't realize that Process value was available.
Well dynamics should have develop the validations that appears with the date and time field in the form controls.
Anyway, there is alternate solution to this.
1st Step: we need JS to record current time to any required field in the form onLoad (onLoad will update the current time every time the form is loaded).
function setCurrentDate(eContext, dateField) { var formContext = eContext.getFormContext(); formContext.getAttribute(dateField).setValue(new Date());
--- this JS can be used globally (in any entity), in the JS you have to parse the date/date-time field's id that will appear in "dateFiled".
2nd Step: Configure the field and Business Rule validating with above field.
Congratulation you are done.
Suggestion to microsoft.
You can add current date time field to global util of d365 and make available in every entity, or else develop addition function in controls of datetime field in the form.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2