• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Date Validation on Field - Dynamics CRM 2011

Hi,

I have created a Date field in the Activity Entity in CRM 2011 and need to set a validation so that a user cannot enter a future date.

Please advice how to set this up.

Thanks
GFC
0
GulfIT
Asked:
GulfIT
  • 2
  • 2
2 Solutions
 
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Hi,

You can use this function on change event of your date field. Just need to change the date field logical name on the first line of the function.

function checkFutureDate(){
	var enteredDate = Xrm.Page.getAttribute("<date field logical name>").getValue();
	var currentDate = new Date();
	currentDate.setHours(0, 0, 0, 0);

	if (enteredDate > currentDate) {
		alert("Future date is not allowed.");
		return false;
	}
}

Open in new window

0
 
GulfITAuthor Commented:
It gave a warning but accepted the value.

Is there anyway to block it from accepting the value if its future date.
0
 
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Add following line before "return false;" statement in the function.

Xrm.Page.getAttribute("<date field logical name>").setValue(null);

Open in new window

1
 
GulfITAuthor Commented:
Thanks it worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now